Execution fails via java -jar while the same code runs fine through eclipse
I have been working on packing a project lately but it has turned into a nightmare. So here's the problem in a nutshell. I have a project that I'd like to have as a jar file, and eventually use it as Java Web Start.
When I try to build and run the code through Eclipse, it works fine. However when I export it as a "runnable jar" and try to run it via terminal I get cryptic exceptions that seem to depend on the referenced libraries. I have checked that the libraries are there in the jar file so it's not that they are missing.
Depending on how I export it the specifics of the exception changes while it seems to originate from the same problem. Below is the stack trace thrown when the project is exported with depending libraries packaged as jars inside the "main" jar.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.ExceptionInInitializerError
at org.eclipse.gef.tools.MarqueeSelectionTool.<init>(MarqueeSelectionTool.java:99)
at org.gvt.MarqueeZoomTool.<init>(MarqueeZoomTool.java:16)
at org.gvt.action.MarqueeZoomToolAction$1.<init>(MarqueeZoomToolAction.java:28)
at org.gvt.action.MarqueeZoomToolAction.createTool(MarqueeZoomToolAction.java:28)
at org.gvt.action.AbstractGEFToolAction.<init>(AbstractGEFToolAction.java:24)
a开发者_开发知识库t org.gvt.action.MarqueeZoomToolAction.<init>(MarqueeZoomToolAction.java:20)
at org.gvt.TopMenuBar.createBarMenu(TopMenuBar.java:113)
at org.gvt.ChisioMain.createMenuManager(ChisioMain.java:612)
at org.eclipse.jface.window.ApplicationWindow.addMenuBar(ApplicationWindow.java:235)
at org.gvt.ChisioMain.main(ChisioMain.java:144)
... 5 more
Caused by: java.lang.IllegalArgumentException: Argument cannot be null
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.graphics.Resource.<init>(Unknown Source)
at org.eclipse.swt.graphics.Cursor.<init>(Unknown Source)
at org.eclipse.draw2d.Cursors.<clinit>(Cursors.java:170)
... 15 more
By the way, I saved the XML / ANT output of the exporting process which I could add her if it could be of interest. I chose to omit it for the sake of less clutter.
Any ideas as to what might be the problem here?
EDIT: I am starting to think if it's a 32/64-bit problem with the SWT-GTK library. Can anyone confirm or deny this?
The exception you have here is not about dependencies. It's a programming error: "some one is passing a null argument to an SWT method that doesn't allow it).
According to the stack trace you are using GEF. How do you run your code in Eclipse, as java application or Eclipse application ?
If you are speaking about Eclipse application, you can't simply export it as a runnable Jar. You will have to create an RCP. Look on Google for RCP tutorial, you'll find many interesting result.
It turns out that eclipse runs the 32-bit JVM on my machine (for some weird reason) and yes it was about the os and arch specific libraries for SWT. For those who have similar problems please refer to the threads below for more info:
Problems with loading resources during execution
Running SWT based, cross-platform jar properly on a Mac
Good luck,
精彩评论