I developed a Java Swing Application. It was developed using Netbeans in OSX. It runs perfectly in nix but when it comes to windows, I get this exception:
NoClassDefFoundError: org/jdesktop/beansbinding/Property
Tried many things like removing and adding libs to the class path again. Googled a lot in vein. How can I fix it?
Problem partially solved. Built the same project in windows and its working in windows. The jar built in nix works fine in nix but shows this error in windows.
Unix (and OSX) have different classpath separator than windows (: instead of ;), check out your startup script or command line parameters.
AS you have already mentioned, issue is with the missing jar file in class path.
Try printing the java class path from code and look out for the missing jar file.
System.out.println(System.getProperty("java.class.path"));
org.jdesktop.beansbinding.Property is part of jsr296, which no longer supported in newer versions of NetBeans. See Why can't I find Java desktop application in Netbeans 7.1 for more.
Once I had the same problem but not with swings with jdbc. I tried a lot and got the solution.
First you make sure that all things said in google and the above answers are done. Still if the problem persists means delete all the class files created before and rerun the project once again, it ll work. Notify me if it works.
Related
I built a javaFX artifact using IntelliJ. My first problem was in the Application Class box, where it didn't automatically detect my main class, or even suggest any classes as main class when I searched in the search box. I saw that it was a bug with IntelliJ, somewhere on StackOverflow, and I just manually entered my packageName.Main in the application class box.
I have two dependencies that I extracted into this output root. The output of building the artifact looks like this.
Then after rebuilding the project the JAR runs on my PC 100%, even if I move the JAR to another directory, it works 100%.
So I copied this JAR (Swansong.jar) to my other PC and when I double-clicked it, nothing happended. When I ran it in the cmd:
java -jar Swansong.jar I got this error:
Error: Could not find or load main class swansong.Main
Caused by: java.lang.ClassNotFoundException: swansong.Main
I read about manifest files but I can't find a manifest file anywhere in my project, but if I extract the JAR file the manifest file that was generated looks like this. Can anyone please help me, why does the JAR run on one PC but not on the other? And how can I fix this?
UPDATE:
This is the contents of my jar file and this is the contents of the swansong directory inside the jar file.
UPDATE 2:
I feel stupid. My main PC runs jdk8 and my other pc runs jdk11. And JavaFX is not included in the jdk11. So I think this is the problem, but not 100% sure yet. Will test and see. Are there any workarounds for this?
I hate to admit it, but the solution to the problem was staring me in the face all along, and I am truly embarrassed. I used Java 8 to develop the program. Target PC was using Java 11 and I never thought to check the JDK version, because I thought I was using JDK8 on both PCs.
JavaFX is included in JDK8, but not in JDK11. It should be added to a project as an external library when using newer JDK versions. I just used JDK8 for running the program and everything works 100%. Thanks for the answers and comments though, I learned a lot about manifests and classpaths trying to solve this problem, so the effort was not in vain!
Any executable jar file needs to have manifest file which points to the main class.
-JAR File
\---META-INF
\--MANIFEST.MF
In the MANIFEST.MF, you should introduce the main class as this:
Main-Class: com.mycompany.MainClass
Class-Path: .
com.mycompany.MainClass should be replaced with appropriate path (fully qualified name of your main class)
I have a code snippet that is part of my eclipse plugin. When testing it in a runtime eclipse version (That means it is not packed into a jar afaik) it runs just fine.
However if I pack my plugin into a jar and then run the respective code snippet it results in a complete crash of eclipse without any error logs (I'm assuming that it even crashes the JVM).
I'm running this on Linux Mint.
According to this post the Desktop API is broken in older Java versions but it should be fixed in Java 8.
Has anyone an idea why this is still happening?
Although this is not an answer to the question why the Desktop API breaks down when used inside a jar file, I want to point out an alternative that I have found (thanks to #Holger) for my case (working with the eclipse APIs):
You can simply use PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(<YourURL>); in order to open the given URL in the system's default browser.
I created a project in java and made a jar.
I did this using maven on a Linux OS.
My problem is the jar compiles and works fine on Linux.
But when it comes to running it on windows it doesnt work really well. As in a jframe will appear but functions wont work.
I was looking at
swtjar
But i hasnt been much help. Do jars not run on different os.
Can anyone point me in the right direction I have no idea why this is.
Thanks
edit I get a NoClassDefFoundError for my gui
It seems that you are mixing Swing components and SWT widget together. Do not do that unless you have special reason. For SWT applications, it do have some difference between different OS as this is the goal.
when you get a NoClassDefFoundError , there seems to be an problem with your classpath.
check if all files on classpath really exists.
I encountered a strange situation and I'm struggling myself, trying to understand which is the problem.
I developed a Java application under Eclipse using Swing and jdbc.
I exported an executable jar file, created using Eclipse under Windows.
When I execute the exported file under Linux, everything is working fine, (both the gui and the database access) except that the JDialogs that sometimes are displayed, are not showing anymore in Linux.
If I generate the jar again, under Linux, (without modifying anything in the source code) JDialogs begin to work again.
What's the reason for this?
It seems that the problem isn't related to my source code, so do I have always to generate again an executable jar for every different operating system?
And again, if it is a problem related to the jar building process, why the only problem occurs with JDialogs?
I hope to be clear
thanks in advance to all
Of course you don't have to build on every platform. The idea is to make it once, run everywhere. Are you using the same versions of JDK/JRE on the Windows and Linux machines? Versions of other tools, e.g. Eclipse, Ant?
There are some Components in java swing that have bugs and may not be platform independant.
Perhaps JDialog is one of those bugs.
I made a simple java program that sends bytes to the parallel port, which uses a .dll along with two other classes (pPort.java and ioPort.java) to accomplish it, and it works perfectly fine.
However, I started making another program on NetBeans IDE which has a similar function. It compiles perfectly, but when I run it I get:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: parallelporttimer.ioPort.Out32(SS)V
From what I understand, it's failing to call the .dll file I put on System32. But I don't understand why, since the other program, which is basically the same but made manually without any IDE, runs fine. Do I have to specify something in NetBeans for this to work? Any help with this would be greatly appreciated.
DLL needs to be in the path or current working directory in order to be loaded.
I'm guessing when you've ran your program without IDE the latter was the case. When you run it from within NetBeans "working" directory is likely netbeans/bin folder, so DLL can't be found. Add its location to path and you should be good to go.
I don't do Netbeans, but it sounds like that Netbeans maintains its own java.library.path. Best what you could try is to specify it yourself as VM argument:
-Djava.library.path="c:/path/to/dll/files"
An UnsatisfiedLinkError message typically indicates that the library path is set but does not include the library that you are trying to load. On Windows platforms, you should extend the PATH using
PATH = %PATH%;C:\path_to_dll_file
On UNIX platforms, you should extend the library path using
setenv LD_LIBRARY_PATH mylibrarypath
However, as far as I can remember (I'm not under Windows), System32 is in the PATH so I suspect NetBeans to overwrite it by settings its own PATH.
To solve this on NetBeans, you might want to check http://wiki.netbeans.org/DevFaqNativeLibraries which is mentioned in this message from Wade Chandler, a NetBeans Dream Team Member ;-)
PS: You can also use the java.library.path system property but keep in mind that this system property only works to resolve the immediate native library that you are loading in your code. Loading of other dependent libraries is left to the first library. The JNI library that you load will rely on the OS dependent way to resolve its references (this applies to the solution of the FAQ too IMO so I'm still not 100% convinced its a good solution).
Have you looked into the two classpaths for both programs (standalone and IDE) ?
In my case the cause was not the missing library, but the use of 64 bit Java JDK as default java platform for Netbeans.
(It did not help to add the "-d32" flag.)
The problem was solved by:
Adding a 32 bit java platform to Netbeans (Menu: Tools/Java platforms) and
Assigning it as the platform for the project (Project properties/Libraries/Java Platform).