Fat jar instantly closes - java

I created a fat jar file using JarSplice, but when I launch it i get a window (the size is okay) and it closes after half a seccond...
In the "add jars" section I'm adding the jar file that I exported from Eclipse, and all library jars that I'm using. In the natives section I'm adding only Windows natives for lwjgl. I think I wrote the correct main class.
What am i doing wrong? How can I fix this problem?
Note: I'm using the newest version of eclipse and jdk.

The file no longer is really on the "file system" but is instead in the jar, so you will need to load the resource from within the jar. When you run from within eclipse it is still on the file system, but when you create the jar it's not, that's why it works in eclipse but not when you package it up. The answer to this question should give you a good start on loading a file within a jar as a resource. That said, I'm not sure if you can do something similar to your listFiles call.

Related

IntelliJ IDEA not recognizing JavaFX library

I am attempting to create a JavaFX project using IntelliJ IDEA. The instructions for doing so appear here: Create a new JavaFX project. This issue is, I am encountering a popup that does not appear in the official instructions, and it is preventing me from using the library.
This is the step I am having trouble with:
However, when I select the lib folder, I see this popup before I am allowed to proceed and pick a module:
No matter which option I pick, the classes from that library are still not recognized in the program. What do I do?
Edit: The lib folder is not empty, so that can't be the cause of the issue.
When you go to the lib folder select all .jar files and src.zip file then press ok. You have to manually add all files in the lib folder.

I created an installer via install4j for my app using a jar generated from maven. Why can't it find the main class when executing the .exe?

Here's how I created a jar file using maven.
​
Now for my JavaFX Application, I'm using afterburner FX Framework. Now I need to create an installer for this app to be deployed to other devices. I'm using Install4j. My steps:
mvn clean package
copy and paste the generated jar file into a different directory
add that directory to install4j Files
on Launcher under Java invocation, I select the jar file, and then I select my main class: `BOOT-INF.classes.inc.pabacus.TaskMetrics.TaskMetricsApplication`
I Build the installer and run it, install to Program files, and then open the exe file
But then an error dialog shows up:
java.lang.NoClassDefFoundError: BOOT-INF/classes/inc/pabacus/TaskMetrics/TaskMetricsApplication (wrong name: inc/pabacus/TaskMetrics/TaskMetricsApplication)
So what I did wrong was two things:
Initially, like way way back, I tried using JavaFX with Spring Framework - unsuccessfully. I'm no longer using Spring, but I still had some leftover Spring in my pom file, which caused it to put the files in a BOOT-INF directory when i package it to jar. I just simply had to remove the Spring leftovers, and the boot-inf directory was gone.
So in install4j, you select a directory that would contain the files you would add to your installer. In the tutorials, they had a separate lib directory which contained external libraries. So I thought that's all I needed. I copied my dependencies into a lib folder via maven, then i put them into a directory along with my jar. So that's all my directory had - the jar file and the lib folder. That doesn't work. I didn't know. Apparently, it needs all the files inside the target folder generated by maven. I should've just used the target folder itself.
So there you have it. I have now successfully created an installer. I do hope no one walks as silly as me, but if you had also encountered the same mess up, well... here ya go.
You seem to have configured
BOOT-INF.classes.inc.pabacus.TaskMetrics
as the main class when the correct package name is
inc.pabacus.TaskMetrics.TaskMetricsApplication
Alternatively, your VM parameters configuration for the launcher is incorrect and includes text that can be interpreted main class.

"Native code library failed to load" outside of IDE when running exported .jar

as stated in the title, my programm won't start outside of Eclipse. I've imported a library consisting of a xy.jar and xy_jni.dll
CMD within the folder of the jar-file:
java -jar myprogramm.jar
is followed by the statement:
"Native code library failed to load. Please add the xy-folder as location for native libraries. java.lang.UnsatisfiedLinkError: no xy_jni in java.library.path
It doesn't matter if I click extract or package ressources when exporting the jar-file.
Also under Project-Settings, Java Build Path, Libraries the .jar & xy_jni(.dll) is added and within all the expandables in libraries the "xy-folder" is set as "Native library location". Also under Libraries I added a "Add Library" named "xy-folder" inhibiting the .jar & xy_jni.dll
When opening the final exported jar-file with a file viewer the xy-folder is included with the xy_jni.dll only, the xy.jar is in the root folder.
What am I doing wrong? Thank you very much in advance!
It's not easy to distribute dll/so/dylib within jar file. The reason here is that you depend on system when it comes to loading libraries.
Typically, libraries have to lay around, somewhere on the file system. This way, they are loaded by System.load and System.loadLibrary.
You can use simple solution to solve this issue. All you have to do, is to extract your native code to some location and load it from there.
Take a look here for a full sample related to loading libraries from JAR:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo035

How do I add LWJGL 3.1.1 to netbeans to use in a Java project?

I want to use the Light Weight Java Gaming Library(LWJGL) to my Netbeans so I can use it in my Java application. The only videos that I can find show the zip file that they downloaded with separate src and doc folders inside of it. The zip file that I download has everything in one directory. I went to lwjgl.org/download and clicked on Stable and then Generate Bundle. What am I missing?
I had the same problem recently.
So, to begin you want to go to Tools in the context menu and select Libraries (as shown). Next you can add a new library and name it e.g. LWJGL-3.1.1 confirm with ok. You can find 3 tabs in the current window Classpath, Sources and Javadoc. There you add your jar files accordingly (in the downloaded .zip file you find .jar files with different names like lwjgl-{whatever}-sources.jar or lwjgl-{whatever}-javadocs.jar) make sure you put them in the right place. You have to repeat this process for all of the jar files you want. The javadoc files are not required but recommended. Make sure you also collect all the native .dll files and merge them in a folder called \natives. You find them in these jar files that are called like: lwjgl-{whatever}-{your-OS}.jar.
Once you have finished the setup for your library right click on your current project and choose Add Library.... In the window that pops up you scroll down until you find your library that you have just created and you are almost done now.
Last but not least go to the project settings. Select Run and make sure that you set the classpath in VM options to something like in the image: -Djava.library.path="C:\java_workspace\LWJGL Library 3.1\natives. Now this classpath tells netbeans where your native files are located. Your \natives folder that you should have created in the beginning is where this path should lead to. That's it. This is all you have to do for a setup without the use of maven, gradle, ...
You can test if it is working with the code provided by LWJGL HelloWorld example.
I hope this solved your problem.
Best regards.

Distributable JAR not working

I created a project in Netbeans 7.1 on my netbook which uses Windows XP. I used the Clean and Build command which created the distributable JAR file in the /dist folder. When I double clicked the file it worked.
Now I sent the entire project folder to my desktop, which uses Windows 7 Ultimate 64 bit. When I double clicked the executable JAR I got an error saying:
Could Not find or load main class myapp.jar
I checked the manifest file and it contains the main class name. Of course, it was autogenerated by Netbeans.
What is going on?
The common mistake is to forget to also take the "layout" folder. If you have used specific features of Netbeans, such as bindings, in the "dist" you have the jar but also a folder with the name "layout" in it and you must also copy it with the jar file and put it at the same target place.
In my case it was a pity having to also send this folder so I decided to stop using binding and other specific stuff and used to reprogram things by hand. Now I only send the jar and it is working.
Note that you can easily know if you have specific features.
Open Netbeans and look in your project folder. There you'll have 2 folder, "Source Packages" and "libraries". Check in libraries. If you have only the JDK it is ok. If you have other libraries listed, then there will be the supplementary folder in the dist and you will have to send it with the Jar.
Hope it helps

Categories

Resources