I'm unable to run jar files of JavaFX applications on my Ubuntu virtual machine and I don't know why. It just says that it can't find the main file of the jar. Other jars of for example Swing applications seem to work fine. This is what I get when I run java -version on Ubuntu:
It seems like it has Java 8 where JavaFX should be included by default, so why can't I run the jars?
Edit: The jar consists of one class that looks like this:
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {launch(args);}
public void start(Stage ps) {
ps.show();
}
}
And it was created with the command jar cfe javafxjar.jar Main Main.class
The jar executes without problems on Windows 10, but fails with this message on Ubuntu:
Today I've also bumped into this problem.
In my case the reason was OpenJDK.
It does not contain OpenJFX by default.
The solution was: sudo apt-get install openjfx
And now all works like a charm.
Could it be due to the JAVA_TOOL_OPTIONS:
$ unset JAVA_TOOL_OPTIONS
$ java -jar javafxjar.jar
Related
OS: Linux Mint 18.3
The combo I want to run is: Groovy 3.0.+ (app and testing code) & Java 11+ & JavaFX 11+
Having had a little help (see comments here) I can now do this using a gradle.build file (including outputting an executable using the Gradle "installDist" task from the application plugin).
I've also managed to do this from a non-Gradle Groovy-enabled project in IntelliJ, by configuring the classpath and module-path appropriately.
My file javaFXTest.groovy looks like this (NB this is the Groovy script which I get IntelliJ to run):
package core
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.stage.Stage
Application.launch( GrApp, args)
class GrApp extends Application {
#Override
void start(Stage primaryStage) {
Parent root = FXMLLoader.load(getClass().getResource("/dialog1.fxml"))
primaryStage.title = "Hello World"
primaryStage.scene = new Scene(root, 1200, 800)
primaryStage.show()
}
}
I'm just wondering, for the sake of interest, how this is actually done in terms of a CLI groovy command. I thought it might be something like this:
groovy -cp .:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/* --module-path /home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml core/javaFXTest.groovy
oops:
Caught: java.io.FileNotFoundException: /home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/--module-path (/home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/--module-path)
... it clearly doesn't recognise --module-path as a configurable option, confirmed by going groovy --help. I searched on this and found nothing. And yet IntelliJ manages to run this script: the --module-path and --add-modules options are added as VM options to the run configuration. Anyone know how this might be done as a CLI command?
On the suggestion by cfrick I found the answer: Intellij does indeed show the whole command in the "Run" view (if you click the '...'):
Turns out this is a giant Java command with all sorts of stuff beyond my understanding, and inclusion of many Groovy .jars for example. I show it in its magnificence for anyone interested: I've split up into lines to show the options a bit more clearly.
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java
-Dgroovy.home=/home/mike/.sdkman/candidates/groovy/3.0.2
-Dgroovy.starter.conf=/home/mike/.sdkman/candidates/groovy/3.0.2/conf/groovy-starter.conf
-javaagent:/home/mike/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.6073.9/lib/idea_rt.jar=41350:/home/mike/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.6073.9/bin
-Dfile.encoding=UTF-8
-classpath /home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-3.0.2.jar org.codehaus.groovy.tools.GroovyStarter
--conf /home/mike/.sdkman/candidates/groovy/3.0.2/conf/groovy-starter.conf
--main groovy.ui.GroovyMain
--classpath .:/home/mike/IdeaProjects/JavaFXExp2/out/production/AppTest:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-test-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-yaml-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-launcher-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-jupiter-api-5.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-jupiter-engine-5.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-templates-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-groovysh-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jsp-api-2.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-dataformat-yaml-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/javaparser-core-3.15.13.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-json-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-launcher-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-xml-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-testng-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jmx-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/commons-logging-1.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-dateutil-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-4.13.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/hamcrest-core-1.3.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/xstream-1.4.11.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ivy-2.5.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-servlet-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/gpars-1.2.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jcommander-1.72.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jsr166y-1.7.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-antlr-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/multiverse-core-0.7.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jsr223-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-sql-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-groovydoc-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/bsf-2.4.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/org.abego.treelayout.core-1.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-core-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ST4-4.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-console-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-annotations-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jansi-1.18.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-datetime-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-astbuilder-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jaxb-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-ant-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-test-junit5-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-swing-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/qdox-1.12.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-cli-picocli-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/javax.servlet-api-3.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-cli-commons-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-macro-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-nio-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-engine-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-commons-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/testng-6.14.3.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-databind-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-junit-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/opentest4j-1.2.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-bsf-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/commons-cli-1.4.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/snakeyaml-1.24.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jline-2.14.6.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-docgenerator-3.0.2.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/src.zip:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx-swt.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.web.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.fxml.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.media.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.swing.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.controls.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.graphics.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-api-2.3.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/activation-1.1.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-core-2.3.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-impl-2.3.0.1.jar
--encoding=UTF-8
/home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/core/javaFXTest.groovy
I hazard a guess that the first -classpath option (with the single dash) is presumably setting that for the "javaagent"... or could it be for the "Groovy starter"...?
This at least solves the conundrum: I had understood that Groovy (even Groovy 3) can't handle Java 9+ modules. So it would make sense that this must be a Java command. Maybe running with a groovy commmand will become possible with Groovy 4, which as I understand it will (hopefully) be able to be able to handle these modules.
I'm getting started with java development. So, I installed JRE and JDK in my computer.
Then, I created a simple Example.java file and saved it in my Desktop.
In the prompt, I executed
javac Example.java
and it worked ok. A .class file has been created in my Desktop.
Then, I tried to run the class, executing this:
java Example
and I got an error in a window alert, with this message:
Java Installation Not Completed
Unable to install Java
There are error in the command line switches: "Example";.
Check that the commands are valid and try again
Then, for testing, I executed both commands:
javac -version and
java -version. Both are installed in my computer.
What am I doing wrong?
I am running Windows 8 and have already set my environment variables.
Example.java:
public class Example {
public static void main(String args[]) {
System.out.println("Finally Java");
}
}
Try to remove installation again, look for all leftovers and remove them manually, if you changed the directory you installed java to, remove environment variables as well and set them again. You should also make registry cleanup: https://java.com/en/download/help/manual_regedit.xml Make installation through offline installer.
I'm trying to compile my programs using the command prompt on Windows 7. I'm having a problem when I during compile. I created a test program:
class test
{
public static void main (String args[])
{
System.out.println("this is working!!!!!!");
}
}
I use the following instructions from the command line:
cd \
cd summer
Javac test.java
java test
I have even tried using javaw and I get the same message but in a pop-up box
Could not find the main class, program will exit.
Any suggestions?
It seems your JDK and JVM have different editions.
You are using different versions of JDK. Check the versions on your javac vs java. This error is telling you that your java and compiled class are not same versions. Check your path for configuration, type "set" in dos to see details.
Example: If you compiled your class with javac (version 7) and execute it with java (version 6)
I have a simple java project (adapted from the example here), which is as follows:
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;
public class HelloWorld {
public HelloWorld()
{
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
group.addChild(new ColorCube(0.3));
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("PATH : " + System.getProperty("java.library.path"));
new HelloWorld();
}
}
My output is:
Hello World!
PATH : /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:299)
at HelloWorld.<init>(HelloWorld.java:10)
at HelloWorld.main(HelloWorld.java:20)
I assume this Exception indicates that the library libj3dcore-ogl.so could not be found. Here's where it is located:
$ locate libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so
As the output above shows, /usr/lib/jni is inside java.library.path. What am I doing wrong? (I'm using Ubuntu 10.04 and Eclipse 3.7.2 - if that may be an issue?)
Java is a bit of unknown territory for me. So please be as verbose as possible on your notes/suggestions/answers.
Update 1
Apparantly it's a 64-bit library (on a 64-bit operating system):
$ file /usr/lib/jni/libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
I use openjdk as runtime environment. Both java3d (libjava3d-java) and the openjdk (openjdk-6-jdk) is installed via aptitude.
Interestingly, it works if I compile and run the application from my terminal:
javac -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld.java
java -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld
But I would really like to use eclipse to do this kind of things.
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
It also works with Eclipse, if I copy the native library (libj3dcore-ogl.so) to the jvm directory and add the libraries (j3dcore.jar, j3dutils.jar, vecmath-1.5.2.jar) as external jars to the build path libraries (right click on project -> Properties -> Java Build Path -> Libraries -> Add External JARs...):
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/
But I wonder if there really is no solution that wouldn't require this copy.
I went through similar issues while trying to run a foreign project requiring java3d. I'm using Eclipse only for the compilation and packaging runnable jar parts (as it is a Maven project), but the runtime errors I was getting were of the same kind. And I want to confirm that moooeeeep's answer was pertinent and very helpful. The reason why I'm posting here is mainly because I think this can be useful for other people to give the full steps (independently from Eclipse, since setting up things using Eclipse facilities or Maven dependency ones failed, in both cases). Everything here is all about setting up correctly the JRE.
Note: I'm working under OpenJDK-7-amd64 (and Debian - 64 bit system). So feel free to adapt the following steps for i386 if applicable (just replace "amd64" by "i386").
Here's what worked for me then :
sudo apt-get install libjava3d-jni libjava3d-java libvecmath-java
This will add required files to be injected in the JRE:
$ locate j3d
/usr/lib/jni/libj3dcore-ogl.so
/usr/share/java/j3dcore-1.5.2+dfsg.jar
/usr/share/java/j3dcore.jar
/usr/share/java/j3dutils-1.5.2+dfsg.jar
/usr/share/java/j3dutils.jar
Since those files are located in different places but definitely not in the JRE's ones, copy (or link) as follows:
Dynamic libraries :
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/
JARs :
sudo cp /usr/share/java/j3d*.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
sudo cp /usr/share/java/vecmath-*.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
Resulting in :
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libj3dcore-ogl.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dcore-1.5.2+dfsg.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dcore.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dutils-1.5.2+dfsg.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dutils.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/vecmath-1.5.2.jar
Hope this can be of any help...
I had the same issue on anothe project, this solved it for me:
Open the run configuration of your project, select the "Arguments" tab and insert the following into the "VM arguments" box
-Djava.library.path=/usr/lib/jni
I don't know why you have to give the path here again. It also doesn't work with relative ones, but this way it works for me.
java.lang.UnsatisfiedLinkError is thrown only if the definition of a native method can't be found.
I'm a newbie to java programming. I downloaded netbeans (java EE) bundle in ubuntu and wrote a simple swing application which runs fine from with netbeans. I tried running it from the terminal by typing "java -jar " as netbeans suggested and i got "could not find main class" error. So i tried to check the classpath by using echo $CLASSPATH and got nothing. Then i set the classpath using $ set CLASSPATH=. When i again tried "java -jar , i got the same error (main class not found). echo $CLASSPATH again gives nothing even though i tried setting classpath. Please help! Thanks in advance
Provide an entry point to the graphical interface. I typically call this class Main
public class Main
{
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyJFrame();
}
});
}
}
Next, click the Files tab (next to projects tab on the top left) and look for a file called Mainfest.mf. You will need to add a Main-Class: attribute to this file.
Main-Class: Main
This tells the jar what to execute when double-clicked or run from the command line.
I don't use Netbeans, but I do know what java wants on the command line when using the -jar option.
One possibility is the jar's manifest is missing a Main-class declaration. This declaration tells where the entry point for the program should be when using the -jar invocation option. It specifies a particular class having a main method.
To verify what I'm saying is the case, try the following on the jar produced by Netbeans (I'm assuming bash shell because of $ prompt in your question .. tell me if I'm wrong):
$ jar xf my.jar META-INF
$ cat META-INF/MANIFEST.MF | grep Main-Class
If that comes up empty, or doesn't name your class, then your next SO question might be "How do I tell Netbeans what class is the entry point when making a jar".