(Disclaimer: I am not a Java programmer, and really have very little idea what I'm doing in Eclipse)
I hacked out an application in Eclipse a while back which I finished off and exported as a JAR which runs nicely. I didn't take any notes or make any comments.
The time comes to make some changes to the project but I have to reload it all again because my PC has since been wiped so some settings etc have probably changed.
Anyway it all works and runs nicely from Eclipse. But when I export as a runnable JAR, and double click to run the application, it doesn't seem to execute.
I can see that there is an instance of javaw running, but no window appears. No errors. Nada.
As I said, it works beautifully in Eclipse. Any ideas?
I have little idea of how I can detect what is going on - as I said, I am NOT a java programmer :-)
Ok then, so you can mark the question closed:
If your Java installation is registered for the .jar extension it will try to run the Jar (i guess that's what's happening). But it will do so quietly.
In order to see what's happening (errors and such) you should try to run it from the command line with java -jar myfile.jar.
Related
I am using a bash script to run my Java program that I made in Eclipse and the Java program is working fine when ran from Eclipse. It has my most recent changes which I can tell by some print statements that I just inserted and ran again.
However, these print statements and all my other changes are not being seen when I run my bash script, which literally just runs the program like this (using testNG):
java -cp ".\src\main\java;lib\*;" org.testng.TestNG ParallelTestXML.xml
I have already cleaned the project in Eclipse and made sure build automatically is clicked, although I think that is to fix if it isn't compiling recent changes within Eclipse. So I have no idea what else it could be.
Because .\src\main\java doesn't do anything useful.
Eclipse has this concept called 'builders' and 'project kinds', and depending on how you've set up your java project, eclipse's build-on-save architecture works differently.
Assuming you just went: "File > New Project > Java Project", and picked all the default options, the way eclipse is set up is that you have a src dir (the fact that you write src/main/java belies that you didn't do this, but I'll continue for the sake of example), and when you save any java file in eclipse, eclipse will immediately update a built view of this, and it will be in a dir hanging off of the project root called bin.
That's where the class files live, so if you want to run off of those on the command line, the right move is:
java -cp ".\bin;lib\*;" org.testng.TestNG ParallelTestXML.xml
Adding the src dir is completely pointless, unless the class files live right next to the source files, in which case calling that dir src is obviously very silly (as a general rule in programming, picking a name that clearly lies, is a very bad idea, for obvious reasons).
If you have some other project setup, for example, you've set it up as a maven project or a gradle project, well, it depends on how you configured eclipse whether eclipse is trying to 'match' the builds, or is triggering a full maven build every time you save, or if you're supposed to invoke maven manually. Most likely the latter. Let maven do the building, and maven will then build your stuff someplace. Generally, {projroot}\target\classes, but to 'run' your app if your app is built with maven, don't invoke java. invoke mvn, asking it to test your stuff. That way mvn will take care of your deps and the like.
I have an exhaustive problem currently boggling me...
I have created a java program through Eclipse and exported to a runnable .jar. Then I have used both Launch4j to create a .exe from it as well as used Inno Settup compiler to create an installer.
Both of these I then copied over to another laptop (Which has Java installed to latest version) I install the Inno setup file and all goes well.
Then when prompted to finish setup and open .exe the program runs and closes just as fast. To be precise the image that I have set as a splash screen flashes once and then closes. I do the same with task manager open and nothing even blips onto the processes panel.
I then proceed to try the same with the Launch4j .exe (It has the .jar in the same folder as the .exe). Same exact behavior as above. Quick flash of splash screen and then closes. Nothing in task manager.
My next step as prescribed by a few other Stack answers is to run via cmd which I do, same story I attempt to run both the newly installed .exe from the Inno setup and the wrapped .exe with exactly the same result and nothing displayed on the cmd window to indicate an error of any kind.
I would much appreciate any help or guidance with regards to this matter? Perhaps someone else has experienced similar?
Extra info.
Virus total returns 0/70 hits for potential threats.
I have made use of only native Java libraries and have no third party packages in the code.
I have not got a certificate as I do this as a hobby for now while I am learning and so have not signed the .exe
So! As an answer to my own question I have discovered what the issue was and will share it here.
Basically boiled down to my jdk/jre being 64 bit and the system needing to be run on being 32 bit.
Easy solution, rewrite program with 32 bit jdk/jre and recompile and it now works perfectly!
I recently wrote an application that is packaged as a .jar file. When I run the application from the command line via "java -jar MyProject.jar" everything looks perfect, just as it does when run from within eclipse. However when I go to the file location in the file explorer and double clock the file, it doesn't quite work. All of the functionality is there, but the GUI is not quite right. All text is much larger, despite the application not changing size, when run like this, to the point where much of it is cut off.
Anyone know whats going on? Thanks!
The cause of this issue was that when being run from the command line, the program was being run with JRE 1.8.0_172, however when being run from the file explorer, the program was using JDK 10.0.1
I noticed that when I build even a very simple Java program in Eclipse, and I try to run it from the Terminal/Command Line and it gives me errors. I noticed after some hunting around that I have to actually compile the .java file I created in Eclipse in the Terminal to create and run the application. However, I can just save and run in Eclipse and get the same output (within eclipse).
I checked to see if I could build the project in Eclipse but the option to do so is greyed out. So, how can Eclipse run it if it actually never gets compiled?
Eclipse does compile it, otherwise it could not run it :-).
Eclipse generates normal .class files, just like javac. It puts them into its "build directory", which you set in the "build path" (or something - Eclipse not handy right now) dialog. By default its under /bin, I believe.
In principle, you can run your program in a terminal using these class files; you just need to set your CLASSPATH accordingly.
In practice, you would either run your program from inside Eclipse (which is for example easier to debug), or deploy your program (using e.g. Ant) to get some kind of installer or installation file, then install that and run it. That way you always run from a complete, correct installation.
Of course for small/simple programs, just running from Eclipse's class files is quite ok.
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.