Reputation: 11
I am new to maven and I am trying to do the maven in 5 mins I have been trying to figure out why mvn package is producing an empty jar. I follow the instructions exactly as told but it doesn't work.
I did the archtype:generate goal. That created the my-app project structure in the /bin. Then when i tried to run mvn package, it said
[INFO] Cannot execute mojo: resources. It requires a project with an existing po m.xml, but the build is not using one.
I tried several suggestions and finally tried putting the pom.xml file inside the my-app project one level higher directly in the /bin.
Now mvn package worked.
A target was created in the same directory as my-app. But the jar was empty...did not have any class files and trying to execute it threw the classnotfoundexception.
Besides is mvn supposed to work only from within /bin. Atleast thats the case with me. But I see several illustrations where they mnv commands are executed from random directories like here
Also how to create multi-module projects on maven?
Any suggestions please?
Upvotes: 0
Views: 3554
Reputation: 178
maven is expecting source files to be present in a certain location. If your setup is messed up, which I think it is, then you will need to explicitly provide a reference to its location using element.
However, it has happened to be once even when everything was correct. Worked on Mac but generated empty jar on Linux. Adding element explicitly fixed it.
Upvotes: 0
Reputation: 128809
mvn archetype:generate
), it creates a project directory for you and puts a pom.xml and some folders and files in it. After reading #2, you should realize that this means immediately after mvn archetype:generate
, you need to cd <project dir>
. Then you're ready to build your maven project.mvn package
will build a JAR (or WAR, EAR, bundle, whatever), and mvn clean
will delete all build artifacts, leaving only the source code.If anything is unclear, just ask.
Upvotes: 0
Reputation: 24722
I think that you tried to run Maven in bin
directory of Maven. You should switch to my-app
directory that was generated and run it there. Maven requires very specific project structure relative to pom.xml. When you copied pom.xml, your java files and resources were left inside my-app, so Maven didn't find any and produced empty jar.
Upvotes: 2