I need to package an application as an executable jar; its properties files will be located outside it, in the same directory. In the end, I will have something like that in the filesystem:
. app.jar file1.properties file2.properties
But, after packaging it, the application cannot access the properties files. After some research, I think I know what is causing it, but I am not being able to instruct Maven to perform as I want.
I am using maven-assembly-plugin to build a jar-with-dependencies, as show below:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>false</index>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
When I try to run the jar, I get an exception that indicates that the properties outside the jar file are not being loaded.
In main.Main class, I put the following code, just to test accessibiliy from outside the jar:
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL systemResource = ClassLoader.getSystemResource("file1.properties");
System.out.println("File 1 " + systemResource);
systemResource = ClassLoader.getSystemResource("insideJarFile.xml");
System.out.println("insideJarFile.xml " + systemResource);
insideJarFile.xml
is a file that is packaged inside the jar. This is the result of the code above:
File 1 null
insideJarFile.xml jar:file:/D:/test/application-jar-with-dependencies.jar!/insideJarFile.xml
Researching for a few hours hinted me that the cause could be the INDEX.LIST file. I opened the jar file in 7-zip and I found it there, inside META-INF folder. I deleted it from inside the jar and executed it again; the result was:
File 1 file:/D:/test/file1.properties
insideJarFile.xml jar:file:/D:/test/application-jar-with-dependencies.jar!/insideJarFile.xml
Question: how I tell maven to not create the INDEX.LIST file? I tried <index>false</index>
but it did not work.
TIA,
FQL