Java Eclipse - Exporting issue - java

I have currently finished my java project in eclipse and now I would like to export it as an executable .jar. The strange thing is, that my program is working fine, when I run it in eclipse, but, unfortnuately, it is not working when I export it.
What should happen:
Well, I have set up a GlobalMouseListener with system-hook-2.5.jar. When I run it as an executable .jar I don't get any input from the listener.
Library is included (I'm working with system-hook-2.5.jar). Is this a problem? It is not the first time exporting a Java Project for me.
Any suggestions, what I could try?

It is always a good idea to start the program via console
Type in
java -jar <Filename>
I got an exception, that causes some problems.

Related

How to solve following error which I get after trying to generate EXE installer file by using Package as -> EXE Installer in NetBeans?

This might be a duplicate, but even after searching I wasn't able to fix my problem, so that's why I am asking here for help.
I have created Java project in NetBeans 12.5, everything runs fine and compiles when I run it through IDE, the problem occurs when I try to create EXE file, by using Package As -> EXE installer option.
Error is following:
C:\Users\Aldin\Documents\NetBeansProjects\Java_CarF_Manager\nbproject\build-native.xml:519: typedef class com.sun.javafx.tools.ant.FXJar cannot be found
using the classloader AntClassLoader[]
When I click onto "C:\Users\Aldin\Documents\NetBeansProjects\Java_CarF_Manager\nbproject\build-native.xml:519:" it opens me build-native.xml file which I have no clue what is it used for and it selects following part of .XML code:
<typedef name="fx_jar" classname="com.sun.javafx.tools.ant.FXJar" classpath="${javafx.ant.classpath}"/>
I've tried to google my problem and before asking question here I previously read that the reason why's this happening is because I am trying to compile a program without required dependencies, now if that's case here I'd like to request some in-depth guide how to setup these dependencies or someone to walk-me-through the process of adding them into my Project, because as I said I pretty much don't have clue about these files.
I am currently running Windows 10 OS.

Cannot run main class file from console but runs from Intellij

I'm a beginner programmer working on my checkers game and I happen to have a problem which seems impossible to overcome. It's probably something obvious and stupid but I've searched for days to get answer and still got nothing.
The problem is I can build and run my application without any problems in IDE (IntelliJ 2021.3.2) but when I try to launch it from console like this:
PS D:\Programiki\Java\polish-draughts\target\classes> java com.polishdraughts.PolishDraughtsWindowed
I get this -> Error: Could not find or load main class com.polishdraughts.PolishDraughtsWindowed
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
Does that mean it doesn't see required dependencies in classes folder? Are they required to be there? If so, how do I force IntelliJ to include them in target/classes? I don't understand why it runs in IDE using play button but doesn't want to start in powershell. Console version of this app, before it included any external dependencies was running from console just fine but now its the same problem. Is my module-info.java file wrong, dependencies don't get exported where they should or what is going on here? In pom.xml i have not specified any scope so it should be "compile" by default according to documentation. I'm totally clueless at this point. I tried to change external libraries to be dunked into lib folder but that didn't change anything. Tried invalidating cache, removing .idea folder, creating new project from scratch and copying just src content over, reloading libraries using "reload project"/"generate sources and update project". Removing iml file (now its completely gone and it doesn't seem to change anything - still app runs perfectly fine in IDE). Maybe I'm launching it wrong?? Please help...
You need to have all the required libraries on the classpath of the JVM.
When you run your JavaFX application in Intellij, and click on the 'Console' you'll see a line that starts /usr/lib/jvm/java-17-openjdk-amd64/bin/java (or wherever your Java installation is). You may need to click on an ellipsis (...) to see the full line.
The line will look something like:
/usr/lib/jvm/java-17-openjdk-amd64/bin/java -Dfile.encoding=UTF-8 -classpath /home/tgdavies/.m2/repository/org/openjfx/javafx-controls/17.0.1/javafx-controls-17.0.1.jar:/home/tgdavies/.m2/repository/org/openjfx/javafx-graphics/17.0.1/javafx-graphics-17.0.1.jar:/home/tgdavies/.m2/repository/org/openjfx/javafx-base/17.0.1/javafx-base-17.0.1.jar:/home/tgdavies/.m2/repository/org/openjfx/javafx-fxml/17.0.1/javafx-fxml-17.0.1.jar -p /home/tgdavies/dev/scratch/javafxdemo/target/classes:/home/tgdavies/.m2/repository/org/openjfx/javafx-controls/17.0.1/javafx-controls-17.0.1-linux.jar:/home/tgdavies/.m2/repository/org/openjfx/javafx-base/17.0.1/javafx-base-17.0.1-linux.jar:/home/tgdavies/.m2/repository/org/openjfx/javafx-fxml/17.0.1/javafx-fxml-17.0.1-linux.jar:/home/tgdavies/.m2/repository/org/openjfx/javafx-graphics/17.0.1/javafx-graphics-17.0.1-linux.jar -m com.example.javafxdemo/com.example.javafxdemo.HelloApplication
Of course the details will be different for your project. This command line will allow you to run your application.
In PowerShell, this works for me (surrounding parameters containing \ with " characters:
C:\Users\tgdavies\.jdks\openjdk-17.0.1\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.3\lib\idea_rt.jar=55078:C:\Program Files\JetBrains\IntelliJ IDEA 2021.3\bin" "-Dfile.encoding=UTF-8" "-classpath" "C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-controls\17.0.1\javafx-controls-17.0.1.jar;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-graphics\17.0.1\javafx-graphics-17.0.1.jar;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-base\17.0.1\javafx-base-17.0.1.jar;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-fxml\17.0.1\javafx-fxml-17.0.1.jar" -p "C:\Users\tgdavies\IdeaProjects\winjavafx\target\classes;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-controls\17.0.1\javafx-controls-17.0.1-win.jar;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-fxml\17.0.1\javafx-fxml-17.0.1-win.jar;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-base\17.0.1\javafx-base-17.0.1-win.jar;C:\Users\tgdavies\.m2\repository\org\openjfx\javafx-graphics\17.0.1\javafx-graphics-17.0.1-win.jar" -m com.example.winjavafx/com.example.winjavafx.HelloApplication

JavaFX "Error: JavaFX runtime components are missing, and are required to run this application" when trying to run fx in vscode

I'm working on a project with a couple friends and we're using vscode so that we can use git efficiently (it's for a school project so IDE is non-negotiable, don't tell me to use a different one) and we're having an issue where neither of them can run this javafx application that I've got in there for testing right now. I was having trouble running it at first and was getting the same error, but I fixed it this morning and now any javafx file I put in there will run fine for me, as long as I have the correct vmargs in the json. However, they're both getting this error when they try to run:
Error: JavaFX runtime components are missing, and are required to run this application
It doesn't say which components are missing or how to fix it which is annoying, but I'm kind of at a loss for what to do. I was having this error, then I added vmArgs to the json to load the proper modules, and it fixed the issue. One thing I've noticed is that when they try to run the file on their end, the json adds new configurations without them telling it to. Even if they delete it, it comes back. But this doesn't happen for me. What am I missing to fix this?
you can run from cmd/terminal with:
cd to ur jar directory
and run:
java -jar --module-path /path/to/javafx --add-modules=javafx.controls(or whatever jars u need from the fx lib) filename.jar

Netbeans JavaSE project works fine when executed but not the .jar builded

I'm trying to build a .jar to deploy my JavaSE application using Netbeans 8.2. Even though the program works well when executing in the IDE, the .jar generated doesn't work : the GUI never shows up and a "javaw.exe" run in background (seen in the task manager).
Is this a known issue ? If so, is there a fix ?
Found my problem : the relatives paths are broken when executing the .jar since it is generated in "myProject\dist" and when executed in Netbeans it's using the folder "myProject\src".
If you have the same problem, I recommand executing the .jar using the cmd, that way errors are shown !

Error when building once built java web project?

When I run for the first time there doesn't show any errors and I did double check the code and there is no error, but once again when I build the file again the following error pops up.
Deleting directory C:\Users\Vbabey\Documents\NetBeansProjects\PersistenceMYEX2\build C:\Users\Vbabey\Documents\NetBeansProjects\PersistenceMYEX2\nbproject\build-impl.xml:1054: Unable to delete file C:\Users\Vbabey\Documents\NetBeansProjects\PersistenceMYEX2\build\web\WEB-INF\lib\toplink-essentials-agent.jar
I cannot understand the reason for the above error? Can anybody explain me what it is?
Based on your comments, you are running into the default windows locking behavior. If you have a jar file open to run an application, you can't overwrite it.
You might be building it when the server is on. Some other application is using your files.
Try switching off the server or other applications that may be using the files.
A quick fix can be to export the project and import it with a different name and then you can build it.
Simply stop the tomcat or kill the java.exe process before building again.
Secondly, I believe you're using Clean & Build option, which does create issue, when the project is already running. Instead just use the build option or run option in case you want to run.

Categories

Resources