Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Export Runnable JAR file(Issues with export)
Export Runnable JAR file [message #835787] Tue, 03 April 2012 13:12 Go to next message
John Klein is currently offline John Klein
Messages: 4
Registered: April 2012
Junior Member
I have a Java Application project that I can run and debug without any issues within ecplise.

I now want to create a runnable JAR file so that I can distribute it.

I right click on the project and select Export->Java->Runnable JAR file. I select the launch configuration for that project and a Export destination.

It creates the jar file.. When I double click it within windows, it didn't open. So I opened a dos window and tried to run it that way.

C:\Test>"c:\Program Files (x86)\Java\jre6\bin\java.exe" ShiftMeter.jar
Exception in thread "main" java.lang.NoClassDefFoundError: ShiftMeter/jar
Caused by: java.lang.ClassNotFoundException: ShiftMeter.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: ShiftMeter.jar. Program will exit.

What am I doing wrong? Why can it not find the main?
Re: Export Runnable JAR file [message #835794 is a reply to message #835787] Tue, 03 April 2012 13:22 Go to previous messageGo to next message
John Klein is currently offline John Klein
Messages: 4
Registered: April 2012
Junior Member
I don't know if this is related or not, but bothers me non-the-less..

When I go to Run->Run Configurations, is shows one configuration and it's under Java Applications.. But, it shows the Name as "ShiftMeter (1)".

If I try to change to the name to "ShiftMeter", it says the name already exists.

This confuses me as I only have one project and that one project only has one Run Configuration.

Could this be part of the issue? And how do I fix it?

Update:
On the duplicate name thingy, nevermind.. I found an option that was filtering it. It was to a previous project that I had deleted.. But I still have the problem in the OP.

[Updated on: Tue, 03 April 2012 13:26]

Report message to a moderator

Re: Export Runnable JAR file [message #835829 is a reply to message #835794] Tue, 03 April 2012 14:26 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1336
Registered: July 2009
Senior Member
The command to launch a runnable jar is java -jar path/to/my.jar. In your case you need to add the -jar prior to ShiftMeter.jar.
Re: Export Runnable JAR file [message #835845 is a reply to message #835829] Tue, 03 April 2012 14:51 Go to previous messageGo to next message
John Klein is currently offline John Klein
Messages: 4
Registered: April 2012
Junior Member
David Wegener wrote on Tue, 03 April 2012 14:26
The command to launch a runnable jar is java -jar path/to/my.jar. In your case you need to add the -jar prior to ShiftMeter.jar.


That got me a step further, thanks..

Now I see the real error, and not sure how to fix.. I'm a C++ developer in a Java world here..

The project uses RxTxcomm.jar/rxtxSerial.dll.. And this seems to be the problem when creating the Executable JAR.. Again, this works fine within exclipse.

c:\Program Files (x86)\Java\jre6\bin>java.exe -jar c:\Test\ShiftMeter.jar
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
        at shiftmeter.io.SerialCommunication.getAvailableSerialPorts(SerialCommunication.java:79)
        at shiftmeter.io.SerialCommunication.promptCommPort(SerialCommunication.java:109)
        at shiftmeter.io.SerialCommunication.connect(SerialCommunication.java:139)
        at shiftmeter.ShiftMeter.initSystem(ShiftMeter.java:176)
        at shiftmeter.ShiftMeter.main(ShiftMeter.java:40)


So I redid the export, except I had it copy the required libs into a dir instead. I saw RxTxcomm.jar but not rxtxSerial.dll. I tried copying into that dir and it didn't fix the issue..

I'm obviously missing something, but not sure what..
Re: Export Runnable JAR file [message #835928 is a reply to message #835845] Tue, 03 April 2012 17:33 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1336
Registered: July 2009
Senior Member
You likely need to get the dll file and any other dll files on which it depends onto your path. You may need to look at the documentation for the RXTX Comm Driver to see if it tells you where you need to place the files.

Sun/Oracle have pretty much abandoned serial communication support in Java, so you are going to be pretty much on your own here.
Re: Export Runnable JAR file [message #835975 is a reply to message #835928] Tue, 03 April 2012 19:07 Go to previous messageGo to next message
John Klein is currently offline John Klein
Messages: 4
Registered: April 2012
Junior Member
Got it figured out.. Duhh..

Double clicked the .jar file within windows explorer did nothing.
Trying to run it without "-jar" mislead me to think it couldn't find the main which is why it wouldn't run.
When I copied over the .dll, I for some reason tried to run the jar with my current directory c:\Program Files (x86)\Java\jre6\bin>java.exe which mislead me to think it still didn't find the .dll.

I rebuilt everything can had my current directory "c:\test", it worked.. Duu.. Once I copied the .dll over, I should have double clicked the .jar within windows explorer as it would have worked.

So all this time it really was just that I didn't copy rxtxSerial.dll to the "working" directory.

Thanks for the help...
Re: Export Runnable JAR file [message #844916 is a reply to message #835975] Sat, 14 April 2012 10:10 Go to previous messageGo to next message
Kennet Jeppesen is currently offline Kennet Jeppesen
Messages: 1
Registered: April 2012
Junior Member
Thank you. It helped me a lot!

However, I can only get it to work through the terminal, and not when double clicking on the jar in windows explorer.

Have you accomplished this?
Re: Export Runnable JAR file [message #880212 is a reply to message #835829] Fri, 01 June 2012 12:27 Go to previous messageGo to next message
Robert Lockwood is currently offline Robert Lockwood
Messages: 39
Registered: October 2010
Location: Riverside, CA, USA
Member
I have a similar problem. I've created a run-able jar Using the Eclipse Export wizard and then do chmod a+x *.jar
When I access the exported jar using the Ubuntu file "explorer" and choose "Open with Java JDK 3.6 Runtime" (or something like that) the code is executed.

it also works I use terminal and type:

java -jar /home/programmer/var/jars/ImageDisplay.jar "/media/sdb1/images/PR-640/PR-640_0003.raw"

But with this code in another class nothing happens:
				String command = "java -jar /home/programmer/var/jars/ImageDisplay.jar " + "\""
						+ ifl[index] + "\"";

				Tell.sendMessage("Execute: " + command); // prints message

				Process p;
				try {
					p = Runtime.getRuntime().exec(command);
				} catch (IOException e1) { // TODO Auto-generated catch block
					e1.printStackTrace();
				} 

The command string that is created I print out and it is:
java -jar /home/programmer/var/jars/ImageDisplay.jar "/media/sdb1/images/PR-640/PR-640_0003.raw"

[Updated on: Fri, 01 June 2012 12:28]

Report message to a moderator

Re: Export Runnable JAR file [message #880344 is a reply to message #880212] Fri, 01 June 2012 17:59 Go to previous message
Eclipse User
Hi,

It probably all depends on the process that is executing the java that
the Runtime.exec() is called in. If the process was started with an
explicit java (i.e. with a fully qualified java) and the process's
environment didn't have that java on the path variable (or whatever the
variable is in Linux) then it wouldn't find just java. It would need to
be fully qualified path to the java file.

Rich Kulp
Previous Topic:help with input images
Next Topic:New to Eclipse, not sure what version is right for my app.
Goto Forum:
  


Current Time: Sat Aug 30 16:32:22 EDT 2014

Powered by FUDForum. Page generated in 0.02247 seconds