I created a Jar file with intellij but it wont run [duplicate] - java

This question already has an answer here:
Maven Shade JavaFX runtime components are missing
(1 answer)
Closed last month.
I used the cmd command java -jar file-name.jar but it wont run.
I get an error in my cmd it states "Error: JavaFX runtime components are missing, and are required to run this application"
I used these steps to create a jar: https://medium.com/#vinayprabhu19/creating-executable-javafx-application-part-2-c98cfa65801e
file but it wont run.

JavaFX support has been removed from JAVA-11. You can find it in older versions. Alternatively, if you want to use a higher version of JAVA you can try the JDK of other vendors such as AZUL OpenJDK which provides JDK with JavaFX support. Alternatively, you can use JavaFX SDK along with JDK which will provide you with JavaFX support.

Related

Java Program Won't Run Due to JRE Version [duplicate]

This question already has answers here:
No JREs installed in the work space that are strictly compatible with this environment
(2 answers)
Closed 2 years ago.
I'll premise by saying I am new to Java
I'm trying to run a program in Eclipse. I really haven't done much at all in terms of building the program, I pretty much just added a GUI using JFrame by following a Youtube video.
My problem is that I'm getting this error whenever I try and run the program:
Description Resource Path Location Type
Build path specifies execution environment JavaSE-14. There are no JREs installed in the workspace that are strictly compatible with this environment. Calculator Build path JRE System Library Problem
I'm running SE-15. How should I fix this?
It appears that you installed the latest version, 2020-09, along with Java 15.
It's useful to know that Eclipse can run with a particular version of Java, even while your applications run in Eclipse with a different version of Java.
You have provided Java 15 to run Eclipse with, and that is what Eclipse assumes it will run applications with, by default.
However, at this point in time, the support in Eclipse for features that are new to Java 15 is experimental. There is an additional plugin you can install that will unlock the Java 15 features, although you probably don't need those yet.
Because the Java 15 features are disabled by default, it's using the execution environment of "JavaSE-14", but you don't have a Java distribution that is strictly compatible with that interface.
As a commenter pointed out, this is only a warning, so it's not likely actually causing a problem. You could likely get by ignoring this warning and focusing on the real errors in your application.
However, addressing the warning could be done in two different ways:
Install a distribution of Java 14, add it to the "Installed JREs" list, and edit the "Execution Environment" for Java 14 to refer to the Java 14 installation
Install the plugin that enables Java 15 features (I haven't done this), and ensure that the project uses the "JavaSE-15" execution environment (install the plugin from the "Marketplace Client", entering "Java 15" in the search field)

How to use JavaFX in Java12 on IntelliJ?

When I am creating my JavaFX file in jdk12, it shows the following error:
The JavaFX run time is not configured. Either use a JDK that has the JavaFX built in or add a JavaFX library to classpath
How can I resolve this?
JavaFX has been removed as of JDK11 this means that Orcale JDK11 and above does not contain JavaFX anymore. You have to get it yourself.
You can use Oracle JDK version < 11 or an OpenJDK that has javafx build in or you can donwload it from here https://openjfx.io/ and get started.
Here is a great SOF question about JavaFX and OpenJDK
HTH

How do I support an application built using Java 1.8 in Java 9?

We have a standalone application built using Java 1.8 and when I test running that application using Java 9, I get a NoClassDefError exception on the javax.xml.soap.SoapException class. I have read enough to know that Java 9 now has the module concept... and that if I add the "--add-modules java.se.ee" option on my 'java' call in the startup script for the application, it then runs correctly.
My question is... how do I still support this application running against a 1.8 JRE? I can't just put the --add-modules option in the startup script since that causes an error when attempting to run against the 1.8 JRE. I really don't want to have to put logic in the startup script to try to determine which version of JRE the user is running and optionally put the new --add-modules option in there.
Any suggestions? Thanks in advance!
You should include java9 specific information 'module-info.java' into your application, so it will not require the command line option. See e.g. here: How to add a Java 9 module via manifest.mf?
The web services module (java.xml.ws, which includes SAAJ) has been deprecated in Java SE 9 with a view to removing it from Java SE and the JDK in the future. The first step on that road to removing it is to not resolve it by default. It is "as if" the module does not exist and this is why you get a CNFE when you run it on JDK 9.
Yes, you can workaround around it temporarily with --add-modules=java.xml.ws (more precise than --add-modules=java.se.ee) and you should be able to get your script to pick this up using the JDK_JAVA_OPTIONS env variable (see http://jdk.java.net/9/release-notes#JDK-8170832) which is new in JDK 9 and so will be ignored in JDK 8.
The alternatives (and the JDK 9 Migration Guide will have more on this) is to move to the standalone version of JAX-WS and SAAJ. These APIs have standalone versions that update at a different pace to Java SE and the JDK. You should find the latest (2.3.0) in Maven for example. The standard versions can be deployed on the class path, and in the future as modules in the event that you migrate your application to modules in the future.
Please take a look at this article. This gives the ways to solve the compatibility concern that you have raised.
https://dzone.com/articles/the-legacy-developers-guide-to-java-9
Please include module-info.java file in your application. Java 9 will consider the same and will be ignored by Java 8.

Can't download Java 7 because my computer already has Java 8

I am trying to download Java 7 on my mac. All my professors require java code to be in Java 7. I have the dmg downloaded but when I double click the icon to install I get the error message :
A newer version of Java is already installed.
The only thing I can do is click close and it exits the install. How can I install Java 7 onto my machine?
If you are doing your "development" using an IDE like eclipse, there is a simple solution to your problem: within eclipse, you can change the "compatibility" mode for your projects.
Meaning - even when only Java8 is installed, you can instruct eclipse that your project should be using Java7 only. So when you write source code that uses Java8 features (like lambdas or such things); you will get compiler errors.
The only caveat: you still could be using classes/methods from the Java8 installation that don't exist in Java7.

java.lang.UnsupportedClassVersionError in eclipse [duplicate]

This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
I am not a Java programmer really, so I am posting this question. The exception is being thrown java.lang.UnsupportedClassVersionError in my main class in an eclipse project. If I comment out the imports that this class has, it compiles and runs fine. If I put the imports back in, it does not work. Does this mean that the libraries I am importing were compiled with a newer or older version of java than I have? when i do java -version on the system i get 1.5_07
I could've sworn this was actually working last week, but maybe some setting in eclipse got tweaked? Is the Java Build Path in eclipse what I need to look for to check the JRE and compiler versions?
In Eclipse, the compiler version is set independent of the JRE version. That means you can set the compiler to Java version 1.6 and use the JRE 1.5. In this case, you compiled classes cannot be run.
You can check the preferences in Window / Preferences / Java / Compiler for the default compiler compliance level, or the properties of your project for a project specific compiler compliance level. Compare that level with the JRE used in your project (Project / Properties / Java Build Path -> Libraries / JRE System Library) and in your program's launch configuration (via the Run / Run Configurations... menu).
UnsupportedClassVersionError means that the Java runtime environment you are using doesn't recognise the version of a class file that you are trying to execute. The most common cause for this error is trying to use a class file compiled for a newer Java version on an older Java version - for example, you are trying to use a class compiled for Java 6 on a Java 5 runtime environment.
As Eugene explained, Eclipse has its own built-in compiler, it does not use the compiler from the JDK - so that's how you can end up with Java 6 class files even if you're running on Java 5.
Christian explains how to set the Java class file version in Eclipse.
Eclipse is not using JDK compiler, but has its own compiler which can produce bytecode for any JRE. You need to make sure that compiler settings in your project are set to the same or lower version as the JRE you have registered in Eclipse. See Window / Preferences / Java / Installed JREs and also check what JRE is used in your launch configuration (see Run menu for that).
If your imported classes come from an external library (i.e., not compiled from sources within your project), then you should validate that the JRE used for your project is new enough for this library.
If you are using Maven with Eclipse, you can use the Maven plugin to update the project and then do a Maven "clean" . This resolved a goofy and unexpected show of this error in my case.
I know this is an OLD thread now but I had a recent adventure with this type of error.
When trying to compile my project within Eclipse using an Ant build file.
Eclipse Kepler (Java 1.7)
Ant 1.7
Project = Java 1.5
All internal paths and compiler settings were amended to look at Java 1.5 and the project built fine in Eclipse.
When trying to compile using Ant I got the java.lang.UnsupportedClassVersionError in eclipse and began looking around - including on here and finding this page.
My resolution was this :
Windows > Preferences > Ant > Runtime > Global Entries
Global Entries was pointing at the Java 1.7 tools.jar
I added a new External Jar (on the right menu) and pointed it at the Java 1.5 tools.jar
I removed the original entry (for 1.7 tools.jar) and my ant builds started working.

Categories