I've my JavaFX app that calls some JNI code, uses a preloader jar and is compiled using jdk 1.7.
Now when I run jar on another computer with JRE7, by:
Double clicking jar: it starts but cannot load the JNI code containing libraries and therefore gets stuck.
Running jar via terminal using "java -jar ": App runs completely normal!
Now if I install jdk on this machine,
it runs fine even with double click!
Can somebody tell me what is difference in these 3 cases?
Try to add logging to your program, so that you can figure out why your JAR file doesn't execute properly.
You should look into if your manifest file is correct - there is a classpath in there you might want to take a look at.
This may have something to do with the fact that JavaFX is not fully released with Java 1.7, but included more as a developer preview.
Also, JavaFX packaging and deployment is a little different than standard Java. There is a new utility called 'javafxpackager' that should be used when packaging JavaFX applications. Check out the documentation here: http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
Related
I think this stackoverflow question already has my answer: IntelliJ runnable jar doesn`t work on other computers
The answer on this question states that most IDEs can autoinclude the needed java libraries to make the jar runnable on pc's without jdk. My question is, where in IntelliJ can I make sure that these libraries are included?
In my project java 15 jdk already shows as external library: link to screenshot
This is what my artifact settings look like: link maybe I need to change something here?
Edit: My question is this: The jar file IntelliJ produces works fine on my computer. On my friends computer excecuting the file gives an JNI error. He only has JRE on his computer and not JDK. I am assuming the problem has something to do with this. How can I make sure the jar file runs on computers without JDK and with JRE?
Your program can run without the jdk but it will need a jre -- the Java Virtual Machine is needed.
You can create this on Java 11 and above using jlink which creates a custom cut-down Java runtime, along with your code, that can be executed on a different computer. However, it will have to be the same architecture/operating system; you can't run the Windows JVM on macOS or vice-versa, for example. Your application code, in the .jar, will be the same on both though.
I have a code snippet that is part of my eclipse plugin. When testing it in a runtime eclipse version (That means it is not packed into a jar afaik) it runs just fine.
However if I pack my plugin into a jar and then run the respective code snippet it results in a complete crash of eclipse without any error logs (I'm assuming that it even crashes the JVM).
I'm running this on Linux Mint.
According to this post the Desktop API is broken in older Java versions but it should be fixed in Java 8.
Has anyone an idea why this is still happening?
Although this is not an answer to the question why the Desktop API breaks down when used inside a jar file, I want to point out an alternative that I have found (thanks to #Holger) for my case (working with the eclipse APIs):
You can simply use PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(<YourURL>); in order to open the given URL in the system's default browser.
I'm in the process of creating a fairly extensive desktop application using SWT. To generate an executable jar file I use maven-shade-plugin in version 2.1. After generating a file, typical double-clicking does not work (the system tries to open a few seconds and stops). Calling from the console
java -jar pakiet.jar
works very well.
Previously, I created a project with SWING with using the same plugin and double click worked without a problem. Is the problem may be to use SWT?
Java version 1.7.0_25
OS Windows 7 Professional x64
You can create a *.bat file with the following content:
start javaw -jar pakiet.jar
I've been using launch4j my my SWT applications, works really well. You can even bundle the jre to avoid any dependencies on the target machine. Supports a splash screen, icon for the exe, you can enforce single instance of the exe, min/max jre versions, graceful error message if jre not supplied etc etc.
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 made a little minesweeper game and I want to send it to a friend so he can test it out. The problem(probably) is that he isn't able to run it because he doesn't have Java for programmers(JDK) installed on his computer. How is it possible to export a program that will work on other computers without having to download any other files**(other than JRE)**?
EDIT: I did read about converting the JAR to EXE but I couldn't find anything that would do it.
EDIT2: Download here the JAR file(it's only supposed to open a blank window). I tested it on two computers with JDK installed and it worked, whilst on two others without JDK(one with the newest JRE) it couldn't start. This is the error:
.
There is no way to "not have to download any other files" - your friend must minimally have some Java Runtime Environment (or just "Java") installed in order to run Java programs.
If your friend has Java installed, you can package your application as a fat JAR so that he only needs your JAR to run your application (depending on the application - but I think yours should be fine).
There are tools available, google "java windows executable" and you will find e.g.
Convert Java to EXE
http://jsmooth.sourceforge.net/
Or already on SO
How can I create a Windows .exe (standalone executable) using Java/Eclipse?
Java Web Start is ideal for this, as it can enable the user to install required components on supported platforms. There's a simple example here.
Not possible, a JRE (Java Runtime Environment) is the least that must be present.
If that is you can just export your program as jar specifying the main class in its manifest. Your friend should if a JRE is installed be able to run the jar file directly.
You could send your friend the compiled binary of your game. In that scenario, your friend will only need to have the Java Runtime Environment installed in order to play your game.
Make executable JAR from it, your friend will still need JRE.