Java .jar file Run Differently from Command Line and File Explorer - java

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

Related

How to deploy a Java command line application?

I started to write code in Java few weeks ago. I use IntelliJ Idea (the latest version) on Win10x64.
I realized a little hangman game (as a Windows command line app) that uses a text file with the words and I have put this text file in a folder called 'assets' inside the project folder (at the same level of 'src' folder). The game works great in the IDE environment but I still don't know how to realize a standalone app and running it outside IntelliJ.
I tried also to compile from command line using javac.exe and it seems that compilation works well but when I try to execute the program from command line using java.exe I get an error that says that the text file I use as vocabulary is not found (java.nio.file.NoSuchFileException).
I have also followed the instructions on Jet Brains site about How to create a JAR file but with no results. Is there a simple way to deploy a Java desktop application so that people (who obviously have JRE) have just to make a double click on an icon and use it?

Create an Exec File in Eclipse

I'm sure the answer is really obvious and right in front of my nose, but I am writing programs in Eclipse and I'd like to be able to run them outside of the workspace. (Like on the command line.)
Problem is I can't find the executable file in the file explorer. So I have to ask....
How do you run programs you write in Eclipse OUTSIDE Eclipse? (Program is in java.)
I just recently switched from Visual Studios to Eclipse so I don't really know Eclipse well. Most of the time figuring out the IDE is more hard to actual coding really.
The executable can be created by Clicking: file -> Export -> As Runnable Jar File
Then make sure launch configuration is set to the correct project, and that the export destination is where you want it to be. Then Click finish, and your runnable jar file should appear where you specified.
If the program has a GUI, it can be run like a regular exe file (double clicking, etc.) if it does not have a GUI it will need to be launched from the command line (ie, by navigating to it with CMD, or with a batch file).

Java .jar doesn't work on other computer

I made a simple card game using Eclipse Kepler. I then exported it to a runnable .jar file.
When I double click the .jar file, nothing happens. So I made a .bat file:
java -jar CardGame.jar
When I run it, it works fine, but when my friend runs it on his computer (yes, both files in the same directory) the cmd.exe will tell him: 'java' is not recognized as an internal or external command
After some searching I read that I had to add %JAVA_HOME% in the .bat file. This made no difference for me, but it will still not run on my friend's computer.
So my questions are:
- What is wrong with my .jar or .bat file?
- Can I run it without the .bat file, if so how?
He needs to have Java installed in the default path.
The easiest way to get that is to go to http://java.com/en/download/installed.jsp and follow instructions until Java is reported installed.
After that your friend should be able to run it.

java: when running jar file from icon Runtime.getRuntime.exec() doesn't work

so I have this problem. I have an aplication, which is using Runtime.getRuntime.exec(adobePath) to run Adobe Reader.
When I run my aplication using NetBeans or from cmd line by using java -jar "MyApp.jar" it does work fine. But when I run jar file by double-click or from cmd using MaApp.jar it doesn't work. I'm using Windows 7.
What can be wrong?
Thanks
edit: Maybe I said it wrong way. When I run jar file by double-click it does run. And it works, but when Runtime.getRuntime.exec(adobePath) is called nothing happens. And It work fine in NetBeans or when I run App by java -jar "MyApp.jar".
Right-click on the jar and see under Open With ?
Make Java Runtime as default program to run with.

Exported runnable JAR file from Eclipse doesn't seem to execute

(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.

Categories