Reputation: 9876
I used Maven shade plugin to build the executable jar, which works fine when it include the properties in the build.
But when I tried to move properties out to a separate folder, it failed with java.io.FileNotFoundException: class path resource [app.properties] cannot be opened because it does not exist
.
I have tried the following three methods, but all failed:
java -cp "properties"
(or ".\*;properties\*"
) -jar app.jar
SET CLASSPATH =.\*;properties\*
As you can see the path separator, I used Windows to run the jar.
[update]
I changed the shade config (from only <mainClass>
to <manifestEntries>
) as below, and it resolved the issue.
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.lifeshield.reminder.App</Main-Class>
<Class-Path>properties/</Class-Path>
<Build-Number>0.1</Build-Number>
</manifestEntries>
</transformer>
@Marko Živanović, thanks for pointing out the -cp
and -jar
usage.
Upvotes: 1
Views: 76
Reputation: 906
You cannot use both -cp
and -jar
options.
If you use -jar
then you have set classpath in manifest file. More details.
If you want to use -cp
then you have to run application by specifying class name. Details.
Upvotes: 1