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.
Related
Sorry if the title is confusing; I am not sure how to word the question.
I am building a Java program that uses Selenium, Apache POI, and GeckoDriver to automate a task. I am wanting to make it an executable so it can run on other machines without IDEs. I understand how to make an executable JAR that can run on other computers, but these other computers will not have FireFox or GeckoDriver downloaded. Therefore, I am wondering how to make my program download the prerequisite software one time so it can work on other machines.
Even if my solution has to just end up getting the other computers to download the dependencies, I was generally wondering how one would go about packaging external libraries, software, etc with a program/what the terminology is.
Thank you in advance, and sorry if this is confusing. First time deploying an application and not familiar with all the terminology.
For Windows based distribution you can make an installer with InstallForge.
Its freeware. You can configure where put your jar, and the shortcuts in Start Menu. And also attach your dependencies installer, and execute commands (e.g run silent install of Firefox) inside the setup.exe generated by installForce.
We currently ship a java(jar) installer of our application. Taking into acount the changes to jdk11 we want our users to have the same easy install experience. So, what we are looking for, is to have just one file that can be run even if there is no java installed, it should just start our old java installer.
Probably, this means that we jave to bundle the jre and have a script that runs the jar, but the problem is how to run the batch file natively ? We need this to work on Windows and Mac. Most tools we are looking into require java to run the wrapped jar.
You have to build 2 different scripts/installers, one for each platform. Even looking at very popular software like Chrome, the platform choice is still there (even though you're usually directed to the correct choice based on the information your browser provides them with)
Depending on how much time you can put in this task, the quickest (and dirtiest) solution would be having an archive for each platform that contains the script .bat for Windows and .sh for OS X together with the jre (also different per platform), ask the user to unarchive and run the script which will run your jar with the packed jre. Otherwise, you'll need to create an MSI/exe for windows and a dmg (or other installer type) for MacOs.
I have done the dmg before with a bundled jre and can try to look for the details if you need them (I no longer have access to the code but can probably find the details). It was a free solution but it did require an OS X computer to create the dmg.
One option that I used before and works very well is install4j but the price is not small.
LE: Self contained packaging - although I haven't used this before, it seems like the best current option for your problem.
And an open source option - packr.
that Self Contained packaging doesn't really help, same for packr, same for launch4j. Because all those just generate a application image with a lot of files and directories.
Problem is before that, as an installer you want 1 big exe (or dmg for mac) that does it all, single click
We are already at the stage like SCP or Packr. Because that is easy or current installer.exe and jre\ sub dir and a batch/sh file besides it. Problem is how to get from that directory structure to a single exe that runs.
So what we should have is something that can zip that in a self extracting archive, when clicking on that it should auto extract to the temp dir of the OS, then run directly a command on it (like a batch file or directly in that extracted dir: .\jre\bin\javaw.exe -jar installler.jar)
But nobody seems to have made such a thing, the closest that we have is eclipse with Oomph:
[1] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor/src/extractor.c
[2] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor.lib/src/org/eclipse/oomph/extractor/lib/BINExtractor.java
problem is a bit that is doing the extracting through java and still wants a vm first.
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!!! :)
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 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.