I have the following piece of code:
fun main(args: Array<String>) {
val urlForCSR: URL = ClassLoader.getSystemClassLoader().getResource("merchant.id")
// also tried ClassLoader.getSystemResource("merchant.id")
...
The following when run from intelliJ works fine and finds the resource. But when run using the bundled jar it gives a NullPointerException
.
- Path for resource:
/src/main/resources/merchant.id
- Path for code:
/src/main/java/Route.kt
Following is the Maven config snippet:
...
<!-- Make this jar executable -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>RouteKt</mainClass> <!-- Class generated (for above main func - named Route.kt) -->
</manifest>
</archive>
</configuration>
</plugin>
<!-- Includes the runtime dependencies -->
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Is there any other war to get URL for the above resource which would work with one-jar or other way of making a fat jar.
Jar content:
jar tf target/Route-1.0-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
merchant.id
RouteKt$main$1.class
RouteKt.class
META-INF/maven/
META-INF/maven/groupId/
META-INF/maven/groupId/TokenGenerator/
META-INF/maven/groupId/TokenGenerator/pom.xml
META-INF/maven/groupId/TokenGenerator/pom.properties
One-jar content:
META-INF/MANIFEST.MF
main/Route-1.0-SNAPSHOT.jar
lib/kotlin-stdlib-0.1-SNAPSHOT.jar
lib/kotlin-runtime-0.1-SNAPSHOT.jar
lib/spark-core-2.3.jar
lib/slf4j-api-1.7.12.jar
lib/slf4j-simple-1.7.12.jar
lib/jetty-server-9.3.2.v20150730.jar
...