Michael
Michael

Reputation: 7438

Jar missing generated pom.properties file when built in Eclipse

My project refers to the generated pom.properties file that Maven generates in:

META-INF/maven/${groupId}/${artifactId}

Which is included (in a Jar) as a dependency in another project. When I build / package the main project with Maven outside of Eclipse, the dependency Jar is built as expected (containing the pom.properties file) and all is well.

However, when I build / run the same (parent) project within Eclipse, it's not there. What am I missing?

Using Eclipse, a Jar library of the dependency is there (in the lib folder), containing everything except the Maven generated files. So in my case:

META-INF/
META-INF/persistence.xml
META-INF/MANIFEST.MF
~~~ snip ~~~

The dependency project exists in the same workspace and I have "Workspace Resolution" enabled.

Looking at the build target folder in Eclipse (\target\classes), I can see all the files that Eclipse uses for the Jar, so I can only assume that Eclipse treats it as a "regular" Java project (despite the parent project listing it as a Maven dependency in the POM) - so Maven doesn't get involved in the packaging.

How can I get Eclipse to treat the project dependency as a Maven project / so that the generated pom.properties will be included in the Jar used by the parent project?


Update

For the parent (War) project, the following structure is generated whenever I use Eclipse to build the project (using "Build Project" or "Build Automatically" not "Maven build"):

target\m2e-wtp\web-resources\META-INF\maven\${groupId}\${artifactId}\pom.properties

This is referenced in the Eclipse deployment assembly:

<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>

So that when the War is deployed to Tomcat, the META-INF\maven... structure exists at the root of the archive.

The dependency / Jar project obviously has the same "Deployment Assembly" facility in Eclipse, so I just need to figure out what creates the m2e-wtp folder on build and apply it to that project too.

Upvotes: 0

Views: 3516

Answers (1)

cello
cello

Reputation: 5486

Actually, I don't think you can with the default Eclipse Jar-Export.

The best you can do if you want to do it from within Eclipse is to have a Maven Build run configuration which doesn't do much differently than using Maven outside Eclipse. But at least you have a button in Eclipse to click do generate the jar, if that's the main reason. But the normal Eclipse functionality to produce a jar (File > Export...) ignores all Maven settings.

Workspace Resolution only works for compiling and running code, but not for other Maven functionality.

Upvotes: 1

Related Questions