JavaFX .jar works on Windows and OSX but not on Linux - java

I'm trying to make a cross-platform JavaFX application, and it works fine on Windows and OSX machines, but not on Linux.
When I try to run it on a Linux machine using java -jar app.jar, this is what I get:
Error: Could not find or load main class app.Main
But the class app.Main is in the .jar, as shown by 'jar tf app.jar':
...
app/Main.class
...
I tried specifying the main class using java -cp app.jar app.Main but I got the same error message.
The .jar was built in Intellij IDEA, using basic JavaFX configuration.
Any help?

So, turns out the problem was that the JRE on the Linux machine was OpenJDK, which does not come with JavaFX, as noted by James_D and jewelsea
After installing the oracle JRE 8, it worked fine

Sorry for the necro post, but I had to take a few extra steps. I had JRE 8 installed, but I still had to point java_home to it.
I'm using a MAC.
The JDK locations are here:
/Library/Java/JavaVirtualMachines (verify this)
The default JDK for my machine was temurin-17.jdk
I had to change it to jdk1.8.0_301.jdk
Steps:
Open a terminal
Type:
vim ~/.bash_profile
I pasted this onto the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
Save and exit vim:
https://phoenixnap.com/kb/how-to-vim-save-quit-exit
In the terminal, type:
source ~/.bash_profile
Restart your terminal
In the terminal, type:
java -version
Make sure it's pointing to the right version
Now navigate back to where the .jar is located.
In the terminal, type:
java -jar myapp.jar
Hope this helps.

Related

java JDK 1.8.0 Win 11 - system variables

I've just istalled JDK8 on PC Windows 11 Home
Now im trying to run simple default program from NetBeans14
In environmental variables:
PATH : C:\Program Files\Java\jdk1.8.0_202\bin
CLASSPATH : C:\Program Files\Java\jdk1.8.0_202\bin
Project build on hard disk
C:\Projects\Hello\src\main\java\pack\hello
on cmd going tn cd C:\Projects\Hello\src\main\java\pack\hello
javac compiles .java file on .class file
command "java Hello" output: Error: Could not find or load main class Hello
Hello.class is there.
checking commands, all works:
java
javac
javac -version
Please to support, or send some similar problems posts.
All web answers are speaking about setting PATH and CLASSPATH, where in my case it already took place.
Thanks in Advance
I tried to follow your steps. I downloaded and installed the newest JDK 8 on Windows 11, and NetBeans 14.
Then I looked through the Environment Variables, and the only mention of Java was in the system Path variable:
You see, I have no CLASSPATH variable, nor haven't I manually set anything. Everything was installed automatically. I have no explicit path to C:\Program Files\Java\jdk1.8.0_... in my Path variable.
And I created a simple app in NetBeans. It runs from NetBeans successfully. Just do "Run Project" (F6) in the NetBeans interface.
If you need to run it from the command line for some reason, this question may help.
If you need to run it on another computer, I would advise you not to do it with cmd. Compile it into jar, then wrap it into exe (in case of Windows) using launch4J.

Can't specify SDK in Intellij on Linux

I am running IntelliJ IDEA 2017.1.6 Pro on a Linux (Ubuntu) machine and, it will not let me select an SDK for any Java project.
Whenever I start up the program and go to "Create a New Project" Java has no SDKs available. If go to new and try to specify where my JDKs are installed (I have a few) it always fails with the same error:
I've tried specifying the locations:
/usr/lib/jvm/
/usr/lib/jvm/java-11-openjdk-amd64/
/usr/lib/jvm/java-8-openjdk-amd64/
/usr/lib/jvm/openjdk-11/
/usr/lib/jvm/jdk-14.0.2/
/usr/lib/jvm/default-java
/usr/lib/jvm/java-1.11.0-openjdk-amd64
/usr/lib/jvm/java-1.8.0-openjdk-amd64
(these last three are all just symlinks)
I know I have a JDK installed for my default Java version. I can compile and run code via command line:
justin#stephanie:~/temp$ ls
HelloWorld.java
justin#stephanie:~/temp$ javac HelloWorld.java
justin#stephanie:~/temp$ ls
HelloWorld.class HelloWorld.java
justin#stephanie:~/temp$ java HelloWorld
Hello, World!
The output of readlink -f $(which java) is /usr/lib/jvm/java-11-openjdk-amd64/bin/java (same location for javac exectuable).
Everything I've looked at online suggest that I should just be able to select /usr/lib/jvm/java-11-openjdk-amd64 as my Java SDK but it is failing. I feel like I must be misunderstanding something essential here as I don't know why this isn't working.
Any help would be useful, I've never used IntelliJ before (I've always been an Eclipse user) and it is very frustrating I can't even create a project in it after a couple hours of trying to mess around with it.
1. Please try first with a newer version of IntelliJ, preferably the most current one (currently this is 2020.2)
2. I had the same problem (with version 2020.2 on my Kubuntu system) and fixed it by simply downloading and installing the SDK via IntelliJ.
The /usr directory is mounted at /var/run/host.
You should find your jdk under /var/run/host/usr/lib/jvm.

Jar file runs on Windows but not Ubuntu (JDK 1.8, compiled with NetBeans)

I made a program with java in NetBeans 8.2 using JDK version 1.8 and the program compiled and ran on my windows machine. I then transferred the project folder containing all files (as well as the jar file in dist) over to my Ubuntu machine.
I entered java -version in terminal and got 1.8.0_252 on my linux machine and got 1.8.0_231 on Windows. I don't think this difference means the wrong version is being used.
When I tried to run the program on Linux with the command java -jar "jarFile".jar I got the error: Error: Could not find or load main class kreact.KReact. I don't understand why this is happening, as the class was found when I ran the same command from Windows cmd to open the jar file.
Thank you for any answers in advance :)

Sencha Cmd 5 + Java 8 Error

After installing Java 8 JDK on my Windows build server, I'm running into the following error when executing the sencha command:
C:\> sencha
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
The Sencha Cmd Guide implies that Java 8 isn't supported yet (however Sencha Cmd works fine on my Mac OS X workstation with Java 8):
Sencha Cmd requires Java Runtime Environment version 1.7 to support
all functionality...
I've still got JDK 7 installed on the server. Is there any way to force Sencha Cmd to use a different JDK install? Changing JAVA_HOME and PATH sysenvs does not work, and editing the registry isn't an option.
UPDATE: I've run across this question where multiple java.exe files cause the same error (and that's definitely a possibility here) however maven, ant, tomcat, jenkins, and a slew of other Java tools are working fine. I've only seen this error with Sencha Cmd.
To make this slightly more concrete, I followed ben's advice and created the following sencha.bat file in my installation directory:
#echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_75
set PATH=%JAVA_HOME%\bin;%PATH%
set SENCHA_HOME=%~dp0
java -jar "%SENCHA_HOME%\sencha.jar" %*
and I renamed the existing sencha.exe to something innocuous. Now I can simply type "sencha" at the command line without extra fuss. Of course, if you have a different minor version of Java 7, you'll need to edit the JAVA_HOME above.
My 'Path' environment variable are mapping 'C:\ProgramData\Oracle\Java\javapath' which contains 3 shortcuts for following files from 'C:\Program Files\Java\jre1.8.0_xx\bin':
java.exe
javaw.exe
javaws.exe
But these files are also present in 'C:\Windows\System32'; if you call 'java' from this directory you will have the same error (Error: Registry key...)
By replacing these 3 files in 'C:\Windows\System32' by the one's from 'C:\Program Files\Java\jre1.8.0_xx\bin'; it will solve the issue.
Try the following workaround to use the latest SenchaCMD working with JDK8:
check your PATH environment variable; especially the correct java installation path(s)
open the command prompt and go to the sencha-cmd folder
to use SenchaCMD just execute the "sencha.jar"-file with java:
java -jar sencha.jar
Now, you should see all version informations about the executed SenchaCMD-Tool.
Tested with JDK 1.8.0u25 and SenchaCMD 5.1.0.26 on W7 Prof. x64
I had this exact same thing, found that I was required to update the sencha cmd itself. I had extjs 5.1 cmd 5.1.0 , downloaded extjs 6.0.1 and tried to sencha app upgrade {new_extjs6_path} my app. Received the above error, figured out I was required to update cmd to 6.0.1 as well.

Change java version (Mac)

I have 2 java versions on my computer:
/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
The 1.6.0 is set to default. How can I make my java programs to run 1.7?
Tried to add:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
to my .zshrc file. But this seems to only change the path for my terminals java command.
Also tried to change the HOME symlink like this:
cd /Library/Java
mv Home Home-1.6
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home
This had no effect at all.
Also tried java changer software:
http://www.guigarage.com/2013/02/change-java-version-on-mac-os/
But no effect.
Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?
I believe OS X (at least 10.8) uses the following paths:
JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
Those are symlinks, which you can update to point to your 1.7 installation.
You can verify this fairly easily:
a) run which java to check which java executable is being executed. In theory, that should be /usr/bin/java.
b) run ls -la on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
on my machine).
I think this should sort your .jar execution issue. If your Java application is wrapped in a .app, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub being used by the .app.
$ edit ~/.profile
#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}
$ java -version
java version "1.8.0_20-ea"
here are the steps:
http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html
You can always add into your profile both on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.

Categories

Resources