I am creating an executable jar with maven and have added the following to my pom.xml under build section
<build>
.....
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/snmp</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
.....
</build>
And I use the maven-shade-plugin to build jar with dependencies.
When I run the command after the build
java -jar jarName
It does not unzip all the files under src/main/snmp directory, for some reason it always unzips one file (the same file) every time. But if I do
jar -xf jarName
this unzips everything correctly.
Any other thing that I need to for using resources from a executable jar?
Java -jar isn’t supposed to extract anything, it’s supposed to run whatever main method you’ve declared in your manifest.
What do you mean by “use resources from an executable jar”? If you mean access resources on the classpath from within the application, if you’re doing it right, it should work fine-but there’s no extraction.