Reputation: 1323
I'm trying to package a very simple app into a jar to distribute to a user. I'm using Eclipse Indigo with the m2e plugin on Mac OS X 10.6.8.
I used the Maven build: package goal to package it as a jar. If I double click on the jar to open it, the GUI opens and appears to be working, but when I click the execute button, nothing happens. (The program works fine if I do Run As... within Eclipse).
If I try to run the jar from the command line, it won't even open the GUI, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: str-profile-comparison-0/0/1-SNAPSHOT /jar
Caused by: java.lang.ClassNotFoundException: str-profile-comparison-0.0.1-SNAPSHOT.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
I extracted the manifest file from the jar, to check the classpath, and it looks like this:
Manifest-Version: 1.0
Built-By: username
Build-Jdk: 1.6.0_24
Class-Path: poi-3.7.jar poi-ooxml-3.7.jar poi-examples-3.7.jar xmlbean
s-2.3.0.jar stax-api-1.0.1.jar dom4j-1.6.1.jar xml-apis-1.0.b2.jar po
i-ooxml-schemas-3.7.jar geronimo-stax-api_1.0_spec-1.0.jar poi-scratc
hpad-3.7.jar junit-4.8.2.jar
Created-By: Apache Maven
Main-Class: com.{companyname}.strprofilecomparison.logic.StrComparatorGUI
key: value
url:
mode: development
Archiver-Version: Plexus Archiver
I have several questions about what is happening here:
Why does the GUI open when I double-click the jar file, but not when I try to run it at the command line?
I'm guessing the classpath needs to define the absolute path to the external jars I'm using, how do I set that in the POM file?
Upvotes: 1
Views: 1285
Reputation: 100013
That manifest says that all your dependencies are sitting in the same dir as your jar. If that's not true, no go.
Personally, I'd use the appassembler plugin to make a device that has a shell script to launch it. Or the shade plugin to make an uberjar that just incorporates them. Or learn about OSX stubs to make an OSX proper .app application.
Upvotes: 1