cannot set classpath with maven-assembly-plugin

D.R. picture D.R. · Mar 28, 2013 · Viewed 13.1k times · Source

I am creating console application. I want to have configuration files outside the jar file in conf folder and want to register this folder as a classpath for my application.

I run mvn assembly:single command , get a jar file, BUT when I try to run this JAR with java -jar MyApplication.jar, it can't read configuration files.

I have this snippet in my pom.xml

<build>
    <finalName>MyApplication</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.7</version>  
            <configuration>
                <projectNameTemplate>
                    [artifactId]-[version]
                </projectNameTemplate>
                <wtpmanifest>true</wtpmanifest>
                <wtpapplicationxml>true</wtpapplicationxml>
                <wtpversion>2.0</wtpversion>
                <manifest>
                    ${basedir}/src/main/resources/META-INF/MANIFEST.MF
                </manifest>
            </configuration>

        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <appendAssemblyId>false</appendAssemblyId>
                <archive>
                    <manifest>
                        <mainClass>com.my.test.App</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.conf/</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

Answer

D.R. picture D.R. · Mar 29, 2013

It was my mistake, I had to put

<Class-Path>./conf/</Class-Path>

and not

<Class-Path>.conf/</Class-Path>