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.
Related
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've recently started learning SWT (on class #4, to be precise) due to business requirements, and previously I had been developing with Swing for 2 years.
We deployed Swing applications as jars with resource dependencies. In SWT, what are the deployable forms and equivalents?
I have questions but since my training is online, I'm on a course-ware and there is no instructor, except StackOverflow:
Can SWT apps be deployed as independent EXE's? And what's with the "Eclipse EXE" thing people talk about? Does it mean that all SWT outputs will be Eclipse based EXEs? Or can they be completely independent EXEs?
If the answer to 1 is yes, how does the compiler produce native win32 executable code? This is one area where I'm thoroughly confused. Typically, a deployable jar is fed to the VM which reads the manifest and does its stuff, but an EXE as output? What's really behind the scenes?
How are external resource bundles managed? At the time of deployment?
Internationalization support?
Thanks.
Deploying an SWT application is exactly like deploying a Swing app, with the addition of several jars and a native library. You must currently be using some tool to make exe files for your Swing app; that tool may or may not be competent to also package up a native code library. It is unlikely that the tool is creating 'native win32 executable code'. Rather, it is packaging up Java class files along with the JRE and a stub Windows PE file.
SWT is developed as part of Eclipse. Eclipse has the Rich Client Platform, or RCP. If you build your Java application as an RCP application, you can use the Eclipse tools to generate an executable package for Windows (or anywhere else). It is not a single executable, it's a directory with an executable in it. However, you don't have to use Eclipse to use SWT.
An RCP application has to use much more than just SWT. It has to be constructed as a set of OSGi bundles that depend on the core Eclipse platform. Once you have such a thing running inside Eclipse, there is a wizard in Eclipse that will create a Windows 'executable' (a directory containing your code in JAR file(s), a lot of Eclipse code in JAR files, the JRE, and a PE .exe stub). You can automate that process from ant, though I've never done it myself. You will need to do book-length reading to get up to speed on all of this, I fear.
There no difference between SWT and Swing in terms of resources and internationalization. Other Eclipse-related libraries include an I18N discipline, but not the core SWT. You just use locales and property files as in any other Java application.
SWT is not Eclipse-based, but the Eclipse UI is SWT-based. Eclipse uses the SWT library for its drawing. It is used a GUI library from the Eclipse consortium, available for many systems. If you want to deploy your normal Java Application with an SWT GUI you just add the corresponding libs and .dll's or .so's. Therefore, everything you can do (deployment) with Java respectively speaking Swing, can be done with SWT, if you provide the according libraries. There are tools and ways to compile everything into .exe's but that is not necessarily needed.
I do not really get the Eclipse EXE thing you are talking about, but eclipse just provides a starter exe, which is basically just a wrapper. Otherwise, some people refer to Eclipse RCP als Eclipse EXE but this is not correct. You CAN use the Eclipse RCP to base your App and this would use SWT as UI library. But you can use SWT all by yourself just as library without the Eclipse trail.
I hope this helps.
You can use a java to EXE wrapper like this one http://jsmooth.sourceforge.net/.
Hope it helps.
Basically you need to get your project running with the conventional java -jar command.
Then create an exe bootstrap program that runs the command when you double click it.
Extra things can be done like checking JVM versions inside the exe program.
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.
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).
I've done several projects and packaged them into jar files, but I've noticed that my jar files run much more slowly than in my IDE.
I use Eclipse to compile and run my programs. In Eclipse, I have everything working. When I package my project as a runnable Jar and execute it by double-clicking, everything still works. But when I have animation, the program runs extremely slowly. Instead of 30 frames per second in Eclipse, I now get about 2 frames per second. The animation is very laggy.
Interesting thing is, when I run the same Jar from the command prompt (java -jar MyCode.jar), the lag disappears and my program works as normal.
I currently have no idea what's causing this problem. My computer is running Windows Vista. I'm using the latest version of JRE and JDK. My program contains an animation, nothing fancy.
Thanx
Solution:
There were several different versions of Java on my computer and an incorrect version was used.
The version of java.exe that comes with Windows is very out of date.
By changing the association of the .jar extension to the more recent JVM you should see much improvement.
You may also consider whether any running antivirus software is affecting performance. Some software treats .jar files as the .zip archives that they are and scans accordingly. Their shell integration might explain the difference between double-clicking and command line as well.
Probably you have associated the double click with some "bad" JVM version.
What I would do is to use processxp from SysInternals to see what's the interpreter your app is using. Probably is only matter to change it to use the same as the command line and the eclipse.
Check that and see if both uses the same JVM ( there's a column names command line in ProcessXP, compare that value )
I hope this helps.