I’m trying to package a web application as a runnable JAR file with Maven. The jar-with-dependencies assembly takes care of including all the dependencies, but I still need to include src/main/webapp.
I managed to add the directory to my JAR with a custom assembly:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>webapp</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/webapp</directory>
<outputDirectory>/webapp</outputDirectory>
</fileSet>
</fileSets>
</assembly>
And it does work, and it’s even possible to use this assembly together with jar-with-dependencies. However, the final JAR contains the webapp directory and all dependencies, but not the class files of my project. My assembly is apparently removing them.
Can I preserve the class files of my own project in an assembly? Or is there another way to add a directory to a JAR?
I’m guessing it’s the other way around, it’s not adding them.
Your class files are inside target/classes and they need to go inside target/webapp/WEB-INF/classes. I’m guessing you need another rule like this: