JavaFX can't build artifact - fx:deploy is not available in this JDK - intellij-idea

I have a JavaFX project that I would like to build as a Jar-file. However, when I attempt to do so, I get an error.
Error:Java FX Packager: Can't build artifact - fx:deploy is not available in this JDK
I found a similar problem on here from last year, but it seemed like they concluded nothing.

This happens because either you have many JDKs installed and compiling by another and running by another or you are using the Javafx Application jar feature when creating artifacts in Intellij which is unfortunately broken. Before proceeding with the below steps make sure that you are compiling with and running with the same JDK version.
Here is you fix it:
1 - Create a Launcher class:
The Launcher class is going to call the main JavaFx class from which your appliaction runs. Choosing to make the Jar directly through the Main class is going to error out giving the following error:
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
Your Launcher class should look something like this:
public class Launcher {
public static void main(String[] args) {
MainGUI.main(args);
}
}
2 - On to building the Jar
You probably still have a META-INF folder from the previous build so delete it.
Build the project as a JAR:
File->Project Structure -> Artifacts -> "+" -> JAR-> from modules with dependancies..
Choose the Launcher class for you main and check "copy to the output directory and link via Manifest" and Press Ok
Press Apply then OK.
go to Build -> Build artifacts-> Rebuild

In the JetBrains website I found a good article about, Package JavaFX applications which was really helpful. In the #troubleshoot section it says that,
Error:Java FX Packager: Can't build artifact – fx:deploy is not available in this JDK
The fx:deploy task was a part of the Ant plugin that was formerly
distributed in ant-javafx.jar as a part of Java Packager. The Ant
plugin is not included in jpackage in the current JDK versions.
If you're using a JDK build of version 9 and later, use third-party
solutions for packaging. For example, refer to section Runtime images
in the JavaFX official documentation.

Related

creating a Minecraft PVP client: error message when running minecraft [duplicate]

What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?
Additional information:
I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.
I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.
A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?
(rewritten 2015-07-28)
Summary: Eclipse had compiled some or all of the classes, and its compiler is more tolerant of errors.
Long explanation:
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn command, this may happen.
The cure is to fix the errors and recompile, before running again.
The setting is marked with a red box in this screendump:
try to clean the eclipse project
you just try to clean maven by command
mvn clean
and after that following command
mvn eclipse:clean eclipse:eclipse
and rebuild your project....
Your compiled classes may need to be recompiled from the source with the new jars.
Try running "mvn clean" and then rebuild
The major part is correctly answered by Thorbjørn Ravn Andersen.
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
Each build (Maven & javac or Eclipse) signals in its specific way when it hits a compile error, and will refuse to create a Jar file from it (or at least prominently alert you). The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.
If you have Eclipse open while running a mvn build, you should disable Project > Build Automatically until mvn completes.
EDIT:
Let's try to split the riddle into three parts:
(1) What is the meaning of "java.lang.Error: Unresolved compilation
problem"
This has been explained by Thorbjørn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
(2) How can an eclipse-compiled class file end up in jar file created
by maven (assuming maven is not configured to used ecj for
compilation)?
This could happen either by invoking Maven with no or incomplete cleaning. Or, an automatic Eclipse build could react to changes in the filesystem (done by Maven) and re-compile a class, before Maven proceeds to collect class files into the jar (this is what I meant by "concurrent operation" in my original answer).
(3) How come there is a compile error, but mvn clean succeeds?
Again several possibilities: (a) compilers don't agree whether or not the source code is legal, or (b) Eclipse compiles with broken settings like incomplete classpath, wrong Java compliance etc. Either way a sequence of refresh and clean build in Eclipse should surface the problem.
I had this error when I used a launch configuration that had an invalid classpath. In my case, I had a project that initially used Maven and thus a launch configuration had a Maven classpath element in it. I had later changed the project to use Gradle and removed the Maven classpath from the project's classpath, but the launch configuration still used it. I got this error trying to run it. Cleaning and rebuilding the project did not resolve this error. Instead, edit the launch configuration, remove the project classpath element, then add the project back to the User Entries in the classpath.
I got this error multiple times and struggled to work out. Finally, I removed the run configuration and re-added the default entries. It worked beautifully.
Just try to include package name in eclipse in case if you forgot it
Import all packages before using it, EX: import java.util.Scanner before using Scanner class.
These improvements might work and it will not give Java: Unresolved compilation problem anymore.
Also make sure to check compiler compliance level and selected jdk version is same
As a weird case, I encountered such an exception where the exception message (unresolved compilation bla bla) was hardcoded inside of generated class' itself. Decompiling the class revealed this.
I had the same issue using the visual studio Code. The root cause was backup java file was left in the same directory.
Removed the backup java file
When the build failed, selected the Fix it, it cleaned up the cache and restarted the workSpace.

Kotlin - Application project template - error main class not found

I am using IntelliJ IDEA 2021.1 (Community Edition) - Build #IC-211.6693.111, built on April 6, 2021.
I created a new kotlin project - project template(JVM): Application, built system: Gradle Kotlin,
project JDK:1.8 version 1.8.0_281.
In the “scr/main/kotlin” folder, I created a kotlin file with a simple code like "fun main(){println(“Hi!”)}.
When I tried to run the file(the build was ok), I got this error: “Could not find or load main class MyAppKt”.
What did I do wrong?
Did you also add your main class to the build.gradle file?
mainClassName = "projectPackage.MyAppKt"
I assume if you are adding the MyAppKt file manually it is not added to the build.grale. But clearly more information about the project would help here. Meanwhile check this post Kotlin - Error: Could not find or load main class _DefaultPackage

Error: Could not find or load main class MainKt in IntelliJ

I'm using IntelliJ.
I can run Java or Kotlin project without any issue but
I can't build Kotlin-JS project
I have the error Error: Could not find or load main class MainKt
My IntelliJ information
IntelliJ IDEA 2018.2.6 (Community Edition)
Build #IC-182.5107.16, built on November 6, 2018
JRE: 1.8.0_152-release-1248-b22 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.19.0-041900-generic
File tree
File tree
My main file contain just :
fun main(args: Array<String>) {
val message = "Hello JavaScript!"
println(message)
}
Run Menu
Run menu
I tried the option $KOTLIN_BUILDED$, $MODULE_WORKIN_DIR$, and to put the path manually but it didn't change anything.
When I'm hovering MainKt with my mouse, a tooltip appear "Class 'MainKt' is in the default package" so IntelliJ see the class.
My project settings seem to be ok
Project Structure part 1
Project Structure part 2
Project Structure part 3
I also tried to
Delete the *.iml file
Reinstalle IntelliJ
Re add the main
Invalidate cache and restarted
Thanks you in advance
The "Kotlin" run configuration runs Kotlin/JVM. To run a Kotlin/JS program as a command-line program, you need to make sure you have node.js installed. Then you can either use IntelliJ IDEA Ultimate with the node.js plugin installed (in which case you will see a "run" icon in the gutter that will produce the correct run configuration automatically), or use Gradle to build and run your program from the command line.
Your main file need to be .kt
You need to create it like this: src ->New ->Cotlin File/Class->File.
NOT like this: src ->New ->File.

IntelliJ Spring Boot: How to create an executable jar

I'm trying to create an executable jar from IntelliJ.
First I got the Java Security Exception and I changed sqljdbc4-4.0 to unsigned. First problem solved.
Then I got Manifest not found. Added META-INF dir to output. Second problem solved.
Next I got the BeanCreationException (unsolved):
Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
In IntelliJ it is working.
I think the resources are not in the output. (application.properties, ...)
In which way do I add the resources or where are they stored in the jar.
I'm using gradle and on the spring boot homepage are only instructions for maven.
You should use spring-boot-maven-plugin or spring-boot-gradle-plugin, depending on your preferred build system.
EDIT:
Just run ./gradlew build
I suggest to dive into this getting started guide. It clarifies a lot of stuff for beginners.
A typical Spring boot project is a Maven project or a Gradle-Project (I only know how to do it with Maven, for Gradle see [luboskrnacs answer][1]). So you just need to run the maven targetpackageand pick the jar form the (created)target` folder
use a shell, go to the project root directory (where the pom.xml file is) and type
mvn clean package
cd target
the there is the xxx.jar file.

Cannot reference jdbc.SQLServerDriver in Eclipse (ClassNotFoundException)

I am trying to use the MSSQL driver for JDBC. I have followed the instructions on how to add an external JAR file to the Eclipse Windows IDE as follow:
- Download the installation from here http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx (Microsoft JDBC Driver 4.0 for SQL Server)
- Extract the zip to a file location I have extracted it here (c:\MsJDBCforSqlDriver)
- In Eclipse Package Explorer right click your project -> Build Path -> Configure Build Path -> Java Build Path -> Libraries Tab- Add External JAR file and then I browse to
"C:\MsJDBCforSqlDriver\sqljdbc_4.0\enu\sqljdbc4.jar"
- I then view the successful reference as in image below including SQLServerDriver.class
When I try to execute Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver") I get a ClassNotFound Exception as below:
I tried all suggestions I could find on Google including setting the classpath in Windows Environment Variables.
Under the Run -> Run Configurations menu item you should find an entry for a Java application with the same name as the class that contains your main() method.
Have a look at the classpath tab. You should find your project listed under user entries. Expand it and see if the Microsoft JDBC Jar is listed.
The class path you use for compilation need not be the same as you choose for runtime, though Eclipse usually mirrors any changes to your build path to any launch configurations.
Your spelling and case for the package and class names look correct (Java is case-sensitive on names).
And yes, learning Java and Eclipse will take effort - Eclipse is quite different from other IDEs and it takes time to get to know it.
I found the answer here: http://code.google.com/p/android/issues/detail?id=27490
Seems like includes under Referenced Libraries is not available at runtime and I couldn't see how to change this in my version of Eclipse
"
Reported by fred...#mobileinteraction.se, Mar 22, 2012
Host OS: Windows 7 x64
SDK tools version: 17
Eclipse version: 3.7.2
ADT plug-in version:17.0.0v201203161636-291853
Platform targeted by your project: 2,2
Version of the platform running in the emulator: 2.2
STEPS TO REPRODUCE:
1. Create a project that uses external jars (in my case android-support-v4.jar ).
2. Added the android-support-v4.jar using Properties - Java Build Path - Add External Jar. Have the Activity extends from FragmentActivity.
3. Clean and run project
EXPECTED RESULTS: Application would run launching the FragmentActivity
OBSERVED RESULTS: Application crashes, android-support-v4.jar is placed within "References Libraries" and thus Android can't find it at runtime.
SOLUTION:
Manualy create a folder /libs within your project, copy the android-support-v4.jar to that folder and the ADT will place it under 'Android Dependencies' and it works.
This is the case for all external jars added using Properties - Java Build Path - Add External Jar.
"
Adding the JDBC driver of MS SQL Server to Eclipse:
Download the JDBC driver and uncompress it
Secondary click in the root of the Eclipse project and go to "Properties".
Now go to the section "Java Build Path - Libreries" y then click "Add External JARs".
Search the "sqljdbc.jar" file in the directory where you unpacked the downloaded driver, double click y finish pressing "ok".
I faced the problem and then solved the issue i.e. If You are using the Tomcat as a server for your Web application, the same Exception was coming as the Driver was unavailable to the project, later I put the jar file (sqljdbc4-2.0.jar) into the WEB-INF/lib folder then it was working