Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pack stuff other than target/classes with maven jar

Tags:

maven-2

jar

I am using maven jar plugin to package the jar file. But it looks like maven jar plugin just only pack the stuff that stay inside target/classes. I am also want to pack all the classes in target/classes and (resource and class) files from many other directories. How can i do that with maven jar?

like image 311
David Avatar asked Jan 29 '26 10:01

David


1 Answers

The resource files stays in another folder of project.

If you can't (or just don't want to) put them under src/main/resources, you can declare additional resource locations using the <resource> element:

<project>
 ...
 <build>
   ...
   <resources>
     <resource>
       <directory> [your folder here] </directory>
     </resource>
   </resources>
   ...
 </build>
 ...
</project>

See Specifying resource directories.

The other classes are generated classes.

The convention with plugins generating sources it to generate them in target/generated-sources/<tool> and a well implemented plugin should add the specified path as a source directory (so that generated code would be compiled). When they don't, the Build Helper Maven Plugin can come to the rescue.

If you are generating classes, why don't you generate them in ${project.build.outputDirectory} (i.e. target/classes by default)? I don't think you can add a 2nd classes directory anyway.

If this doesn't help, please clarify your exact constraints and requirements.

References

  • Specifying resource directories
  • MavenPropertiesGuide
like image 101
Pascal Thivent Avatar answered Feb 01 '26 02:02

Pascal Thivent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!