views:

192

answers:

2

Hi,

I'm having (a strange) problem when executing a maven generated executable jar:

user@host$ java -server -jar MyJar.jar 

Error

(and nothing more than this!!!)

Do you have any idea what this king of error comes from ?

In my pom.xml, I copy all the dependencies to a lib folder with:

<plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/${artifactId}-${version}/${artifactId}-${version}/lib</outputDirectory>
                    </configuration>
                 </execution>
            </executions>
       </plugin>

And then I generate a .jar including the classpath (+ a prefix pointing to the lib folder):

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                 <outputDirectory>${project.build.directory}/${artifactId}-${version}/${artifactId}-${version}/bin</outputDirectory>
                <finalName>MyJar</finalName>
                <archive>
                    <manifest>
                        <mainClass>
                           com.company.package.Main
                        </mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>../lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

The generated MANIFEST.MF seems to contain the proper classpath.

Thanks a lot for your help!

+1  A: 

The error isn't saying much and this is indeed weird. Are you using Sun JDK?

Anyway, I don't really get how the dependencies get bundled into the final JAR with your setup and I don't think it contains everything required (I may be wrong of course).

Actually, I wouldn't even try to fix your current setup. To create an executable jar, you should prefer the assembly plugin. See this recent answer for example. Please modify your pom.xml with the suggested configuration (this will take 30 seconds) and try again. Then, please update your question with the new result/error, the pom.xml and the manifest.

Pascal Thivent
I'm actually using the assembly plugin to copy configuration files and some deployment scripts. I don't even know if it's possible to bundle dependencies within the jar. In any case I prefer to keep them outside because I've quite a number of dependencies
emathias
Ah, and thanks pascal for the help
emathias
A: 

I created a new Maven repository, rebuilt all the maven dependencies and somehow the issue was solved.

I've no idea how this happened, because I was just able to run without the jar ...

But thanks for your help anyway

emathias