I'm currently working on a assignment for school and I'm finished programming but I got a major issue.
When I run the program in the netbeans IDE everything works the way it should and its very smooth.
But when I try to run the Jar file it lags and my timer takes 3-5 seconds per second.
Is there something I should check before exporting the Jar file or am I running it the wrong way?
It does the same thing on my Windows 7 64 bit system, Ubuntu 12 64 bit, Ubuntu 11 64 bit and on a windows 7 32 bit. So its not a OS problem. And I do have the new java runtime
My first thought is that maybe Netbeans runs the jvm for your program with more memory. Try to run your jar with increased jvm memory settings. You know it's one of those java options like -Xmx512m when you run the java -jar -Xmx512m yourjar.jar at the command line.
Another guess here, Netbeans is probably executing your pure .class files instead of one packaged jar file. If you can printout the classpath, you can try executing it the same way netbeans does. It may end up where you have to deploy multiple jar files to avoid this issue. Are you using many other jar files in your code?
This is based on my experience using eclipse and having it execute things differently in the IDE versus an exported jar file.
The JAR is probably built with compression by default. Built your JAR manually and specify the 0 option (no ZIP compression). It's worth a try.
See here for more details about the options available when creating a JAR.
If u have eclipse INDIGO version just right click the project node and click on export, then select "Runnable JAR file" under java section click next then finish and its done!!! :)
Related
I'm experimenting with Java for the first time.
I'm using Intellij IDEA and creating a simple app.
In the IDE it's working fine, then I create a JAR artifact and run it like this:
java -jar myappname.jar with no problem.
Now I would like to start the same JAR with double-clicking it from explorer but nothing happens, why?
Please note that if I double click another JAR (sikulixsetup-1.1.3.jar) it starts correctly and show the gui, so the problem is not type association in windows.
My test app does not have a gui but I know if it runs correctly because it's automating windows using Sikulixapi library, so I see if it's doing something or not.
thanks!
Ok, I solved my issue.
Usually the JAR runs without any problem by simply double clicking it in windows,
in my case it was not running becase the .jar files was associated to the 32bit version of javaw.exe while the code in the JAR was expecting the 64bit environment.
Changing the .jar type association in windows from 32bit to 64bit version of javaw.exe solved the issue
Its because jar is not executable binary but plain zip archive. OS cannot execute that. That is why you must use java executable and pass archive as argument to run your application.
If you want your app to be "clickable" you must use some wrapper solution like http://launch4j.sourceforge.net/
Change the default program to use while opening the file from one Java to the other (32 to 64 bit or vice-versa).
I am using Excelsior to make my jar executable into a .exe and I'm getting errors when putting the exe and folder contents on another computer. The program packs what looks like the java run time into a folder called 'rt'. The .exe runs fine on my own computer but when I try on others I get this error:
Invalid Excelsior JRE directory "C:\ programFolder\rt": path canonicalization failded
Anyone know what could cause this error or if you have used Excelsior could you help me out with this? I have posted on their forums but with no luck.
Are you sure you are copying the EXE file that was processed by the packager (JetPackII), not the EXE emitted by the compiler?
Also make sure to install the latest updates (for Excelsior JET 9 it is Maintenance Pack 2 as of today.)
I wrap my Java project's JAR file to an .exe file using launch4j, which works fine on my dev machines and several other computers. However, one user reported he cannot run the .exe file on his machine, as a popup message tells him
Could not find the main class.
Interestingly, the user is able to run the JAR file directly on the same computer, either by calling it via java -jar from command line, or directly by double-clicking the JAR file in the Windows explorer (or via shortcut). That user has installed latest JRE.
I have seen on other threads here that this problem could occur because of invalid Manifest files, e.g. if the main class is missing there. However, I think this is not the case, because it's working fine if the JAR is called directly as said.
So I assume the problem is somewhere with my launch4j configuration. There I have not specified a custom Manifest file, only the input JAR file and the output .exe file.
I thought my launch4j config would be fine, because the .exe is running on several machines using different Windows versions. This is the first time I encounter that problem, but as said with the .exe file only.
Any ideas?
We just found the problem with that one client machine. It had the 64 bit version of the JRE installed, that was causing the problem. After replacing it with the 32 bit JRE version the .exe file can be correctly started again.
Yes,even I faced this problem. I used jar2Exe instead of launch4j. It's working fine.You better use it.
This is my first question, so apologies for any mistakes. I'll try and give all the info I can. Basically I've written a simple swing application which just loads in image into a JPanel and displays it. I'm using Netbeans 7.1 and I have the latest version of the Java SDK.
Anyway, I've used the "Build" feature in NetBeans 7.1 to deploy my application into a Jar file. When I double click the Jar File on my PC, it runs without a problem. However when I put it on other computers (Tested on 2 others so far, both with the most current JRE) it fails to open, citing the following error:
could not find the main class: swong.Startup. Program will exit
swong is my package name, and Startup is the location of my main method. I have checked the manifest file which is created with Netbeans' build, and it[the manifest] does indeed contain the location of my main method class.
From searching, I've come across similar issues in which the classpath is set wrongly, but I don't understand how this could cause my particular error.
If someone could help me, I would be over the moon. I've been studying java for a year or so, and I've got a good handle down, but I've NEVER been able to make a Jar that runs on a computer which wasn't my own. So, 10 points and thanks in advance.
xo.
EDIT: Thank you for the responses. I'm doing shift work and swamped, but I will test and poke with these responses tomorrow and provide more information. Thanks again. xo
I had d same problem while distributing my app. There is 1 solution that you create a batch file with 'java -jar AppName.jar' and asking user to double click on this batch file to execute your app. What i did was to provide a JRE installation exe(eg: jre_1.7.0) with your app.
Now create a Batch file (install.bat) in which write following commands
jre_1.7.0 -> this will install jre on user's pc
set path="C\Program Files\Java\jre_1.7.0\bin"
java -jar yourAppName.jar
Why i installed JRE because different people have different JRE versions installed. So this makes it difficult to set path to the installed JRE's bin folder & calling the 'java -jar' command. Hence as you know which folders your JRE installation will create hence it is easy to set path and execute your jar file with 'java-jar' command.
Check that your jar file has the following structure (at least)
jarfile.jar
|---------- swong
|---------- Startup.class
|---------- META-INF
|---------- MANIFEST.MF
It seems like the class "Startup" is missing. Maybe your jar only contains the .java files, not the compiled classes.
This error message can be a mistakable java7 error, when you try to start java7 compiled classes with a different Java Runtime Environment then java7. Have you validated, that your .jar is started within a Java7 environment on those other test machines? Sometimes it happens, that you have installed different versions of JREs and you might not be sure which one is actually started.
To check which enviroment is used, you can check in your registry for the following value:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
this should point to your latest JRE. Or if you'd like to stay compatible to java6 as well, define the appropiate compile level in your build environment.
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.