Reputation: 9459
I'm using one-jar to package up my program. I have resources in src/main/resources. The maven-resources-plugin correctly copies the resources into the jar, but the jar produced by onejar does not contain my resources.
Here's my pom:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ziroby</groupId>
<artifactId>resourceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>resourceTest</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
</project>
What am I doing wrong? How do I include resources in one-jar?
Upvotes: 3
Views: 1620
Reputation: 1
If you are using something similar to:
getClass().getClassLoader().getResourceAsStream
Try instead using: Thread.currentThread().getContextClassLoader().getResourceAsStream
Upvotes: 0
Reputation: 9459
I have discovered my error. It was putting it in the jar, just not where I expected it to be. It's contained in a jar inside the main jar. Specifically, resourceTest-0.0.1-SNAPSHOT.one-jar.jar
contains resourceTest-0.0.1-SNAPSHOT.jar
, which contains my resource.
Now I just need to find out how to access the resource, but that's another question, which warrants more research.
Upvotes: 2