First off. I am a newbie and green with respect to Java programming.
I created a Java Eclipse "SWT" "Application Window" on a Eclipse Kepler 4.3.1 (32-bit) running WindowBuilder and SWT (swt.jar). The design view is a composite.
The java application runs fine from Eclipse. I simply press the play button and presto.
Problem:
Issuing
java -cp . PkgNetAccelerator32.netAcceleratorApp
yields the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
I was doing some research and several posts on other issues suggested that the cure is to create a manifest. I saw an article that said something like:
Select the src folder, right click and select export, then Java, then JAR file, specify Manifest.jar and a path on the folder, make sure the "Generate the manifest file" is selected, and press finish.
I created the manifest file and tried launching it with the following command line:
java -jar ../Manifest.jar -cp . PkgNetAccelerator32.netAcceleratorApp
That yielded the same error message above.
I saw another article that said that one should add in the swt.jar file, but that is taken care of by the manifest. No? Specifying "swt.jar" instead of the manifest that I created resulted in an error message:
no main manifest attribute, in ../swt.jar
That error message makes sense.
I am at a loss. How do I run the java application?
I am testing on my Windows 7 Professional 64-bit desktop, but I need to run on CENTOS too. That should be no problem, as I assume whatever the fix on Windows is, will work on CENTOS.
UPDATE:
I placed the two lib files in a /lib folder to match the answer given. I then issued the following command line and got the following error message.
C:\SoftDev\Projects\NetAccelerator\JavaWorkspace\NetAccelerator32>java -cp "bin/*;lib/*" PkgNetAccelerator32.netAcceleratorApp
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at PkgNetAccelerator32.netAcceleratorApp.open(netAcceleratorApp.java:43)
at PkgNetAccelerator32.netAcceleratorApp.main(netAcceleratorApp.java:33)
I found the following article, which produces a command line that works, just that is not reasonable for sending. I much rather use the answer.
Lets assume you have a eclipse project structure similar to this:
Workspace
-> Project
-> src (source code directory)
-> bin (compiled byte code directory as JAR)
-> lib (jar directory)
-> .classpath (eclipse file)
-> .project (eclipse file)
I am assuming that you are exporting the JAR as an executable JAR.
So in order to run a class in that exported JAR with another JAR from the lib directory (swt.jar) while your working directory is the Project directory you will need to execute:
java -cp "bin/*:lib/*" PkgNetAccelerator32.netAcceleratorApp
Using wildcards requires Java 6 or later
Please note: CENTOS requires : as a path separator. Windows uses a semi-colon.
This will add your classes and the swt classes onto the classpath and run your main class PkgNetAccelerator32.netAcceleratorApp
SWT 32bit vs 64bit
You will either need to use a 32bit JVM locally or continue to use a 64bit JVM and use the 64bit version of swt; see swt on windows 64 bit. I would suggest you match your version of your local JVM (32bit or 64bit) with the version that you will be running on the CENTOS machine. You will however need a different swt jar for CENTOS.
Related
I have a Java Project (an application to play connect 4) and I want to turn it into an executable file. I created this project in VsCode, and I am using the Java Language Server (see details below). I extracted the .jar file, and used Launch4J to turn it into an executable, and when I run it, I get an error message (see below).
I researched the problem, and it seems that I need to compile my code targeting Java SE 8 rather than 17 (I have 17 currently installed). Could anyone explain to me how I should do this, or is there anything else I'm doing wrong?
The project has multiple files. I'm not sure if this is relevant, but the project has no external dependencies, although it does use javax.swing, javax.sound, and java.awt (as well as java.io.File, java.io.IOException, and java.util.Random, but I'm pretty sure those are irrelevant).
I have eclipse installed if it's necessary, but I only installed it today, and have no experience using it at all. The JDK I am using is (I believe) version 1.8.0_321. (At least this is what I get when I type in java -version.)
The Java compiler version is javac 17.0.2
When I try to run the executable generated by Launch4J, I this is the error I get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 61.65535), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
And the popup error:
Java Virtual Machine Launcher
Error: A JNI error has occurred, please check your installation and try again.
Here are the Settings I used in Launch4J:
Output File: C:\Users\username\OneDrive\Coding\Java Connect 4 v.2\Connect 4.exe
Jar: C:\Users\username\OneDrive\Coding\Java\Java Connect 4 v.2\Java Connect 4 v.2.jar
Don't wrap the jar, launch only: NOT ticked
Wrapper Manifest: none
Change dir: .
Command Line args: none
Process priority: Normal
Both Options NOT ticked
Min JRE version: 1.2.0, Prefer public JRE, but use JDK runtime if newer
Max JRE version: none, First 64-bit, then 32-bit. (This was the default.)
All other settings are default.
Download the latest Java JDK version as .exe file (“x64 Installer”) and install by clicking on the .jar file.
Now the server should start again
#Holger has answered this question. The answer to the problem was to ship a custom JRE image with the application with the help of JLink. That way it can be used regardless of the local version of JRE.
Hello when i am running my application from Eclipse it runs perfectly but when i export it as a runnable jar, it doesn't run.
When i try running it from cmd it gives me one of 2 errors the first errror is after i just export it with the "copy required libraries into a sub-folder":
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:189)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:180)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:137)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:948)
at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:280)
at javax.media.j3d.Canvas3D.<clinit>(Canvas3D.java:3862)
at Main.Game.<init>(Game.java:39)
at Main.Main.main(Main.java:6)
when i change the sub-folder's name from IslandDomination_lib to just lib it gives me another error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D
at Main.Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: javax.media.j3d.Canvas3D
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I have tried running it several ways:
1.
java.exe -jar IslandDomination.jar
2.
java.exe -cp "lib/j3dcore.jar;lib/j3dutils.jar;lib/vecmath.jar" -jar IslandDomination.jar
3. using another java program to run it for me:
package main;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException{
ProcessBuilder pb = new ProcessBuilder(System.getProperty("java.home")+"\\bin\\java.exe", "-cp" , "\"lib/j3dcore.jar;lib/j3dutils.jar;lib/vecmath.jar\"" , "-jar" , "IslandDomination.jar");
pb.directory(new File("./"));
Process p = pb.start();
p.waitFor();
}
}
The internal structure of my jar consists of 4 folders:
J3DBool
Main
Maths
META-INF
The folder with the required jars is in the same folder as the main jar
You use a completely obsolete version of Java3D, which is very difficult to bundle in any software as you have to set the Java library path somehow and you have to bundle both the Java libraries and the native libraries. Rather rebuild your project with Java3D 1.6.0 pre 12, it's a lot easier to use as this version relies on JOGL 2 which uses automatic native library loading and everything is packaged as JARs, there is no longer any need of modifying the library path, just take care of the classpath.
Please follow my tutorial, especially the very last section with (a lot) more information.
Finally, the obsolete version that you use isn't guaranteed to work on any recent operating systems. If it works, you'll be lucky; if it doesn't, nobody will fix it.
I think the required library file (jar file) not found in the classpath.
you need to set Library file in your class path.
step to set class path:-
MyComputer->Properties->Advanced system setting->Environment variables
find "classpath" either in user variables area or in system variables if found edit that and put all the jar file link. if not found then create new(click on new) and put all the jar link there and try to run your application
I found out how to fix my problem and it is done by simply putting the needed dll files next to the executable jar file
I have made my own Minecraft Client (which runs fine in Eclipse) however once I had exported it as a .jar file, and put it in Minecraft versions folder with a .json file, it returned an error when loaded.
UPDATE------------------------------------------
Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.minecraft.client.main.Main.main(SourceFile:41)
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
I did the instructions to successfully export it, however it returned this!
Yes, of course it runs fine in your IDE.
Have you noticed that it has 1.8.jar under Libraries tab? That means the "Client" in your Eclipse project is using some files(assets.*) inside 1.8.jar. The Client project in your Eclipse isn't the original Minecraft source code. It is modified a bit by MCP scripts to allow you to launch Minecraft client properly in your Eclipse. You have to copy a lot of stuffs from 1.8.jar and I am sure that Minecraft Launcher can't launch it unless you modify your exported Jar file and *.json.
If you really want to have your own Minecraft.jar, below are the correct steps.
After you've done your modifications to Minecraft, save all files then close your Eclipse. In the directory(folder) which contains eclipse directory, you should fine reobfuscate.bat or reobfuscate.sh. Use the .bat version if you are Windows user, and use .sh if you are MacOS or Linux user.
After you run the file, you should see some files in reobf directory. The files in the directory are obfuscated files and can be copied to Minecraft.jar directly. Now, use WinRar or other tools to open Minecraft.jar(1.8.jar). Copy all the files in reobf directory to Minecraft.jar(and replace if the file exists). After you finished these steps, you've got your own Minecraft.jar!
Now you should create your own version profile in Minecraft Launcher.(Reference: here)
In your .minecraft/versions directory, you should put your own Minecraft.jar. Predict you named it MyCustomMinecraft.jar, you have to create a new directory called MyCustomMinecraft in .minecraft/versions. Now, copy MyCustomMinecraft.jar and paste it in MyCustomMinecraft directory. Then, copy 1.8.json in versions/1.8 directory and paste it in MyCustomMinecraft. Rename 1.8.json to MyCustomMinecraft.json. Open MyCustomMinecraft.json with any text editor, in line 2, you should see "id": "1.8",. change it to MyCustomMinecraft. Your line 2 should look like "id": "MyCustomMinecraft", now.
Open Minecraft Launcher. Edit Profile button > Use version: > you should see release MyCustomMinecraft in the list!
I made a Java game in eclipse and when I run the executable .jar it starts up, and the loading screen starts, but then it stops and hangs. I ran it using the command line: "Java -jar filename.jar" and when the loading screen stops it displays an error. This is what the cmd shows:
E:\>Java -jar Speedrunner.jar
60Ticks, FPS:1447
60Ticks, FPS:1627
60Ticks, FPS:1380
Wed Mar 19 12:02:27 GMT 2014 INFO:Initialising sounds..
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: no lwjgl in java.
library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.openal.AL.<clinit>(AL.java:59)
at org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
at org.newdawn.slick.Sound.<init>(Sound.java:83)
at com.daves.first_Scroller.utils.AudioPlayer.addSound(AudioPlayer.java:29)
at com.daves.first_Scroller.utils.ResourceLoader.loadSounds(ResourceLoader.java:35)
at com.daves.first_Scroller.Game.load(Game.java:110)
at com.daves.first_Scroller.Game.tick(Game.java:160)
at com.daves.first_Scroller.Game.run(Game.java:228)
at java.lang.Thread.run(Unknown Source)
This is saying that LWJGL isn't in java.library.path I've gone to my game in the workspace and configured the build path to include all the libraries and to include them in the .jar when I export my game but I'm still getting the same problem. Does anyone know what I need to do to get this to work? (I looked in the .jar and LWJGL is there in the org file)
Export lwjgl library in your jar.
To do this, right click on the project, properties, java build path, order & export, check your library
Set the (native) library path in the command line:
Java -Djava.library.path=path/to/dir -jar filename.jar
Where dir:
[...] should contain the native part (*.dll files on windows, *.so on linux,
*.jnilib on mac, etc)
(Source)
You need to do two things: you need to include the LWJGL classes on your classpath (or in your jar), and you need to include the natives in your library path.
Exporting from eclipse doesn't automatically include your library path, which is why you're getting your error.
A utility like JarSplice or SvgExe can help with both of these things.
I m trying to compile an open source software . The build works fine and results into a jar file "five-server.jar". When I try to run this file from cmd , I get these errors.
C:\Users\vickey\code\five-server\dist\main>java -jar five-server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.devtcg.five.Main. Program will exit.
any suggestion what is wrong?
The SWT Jar files are platform dependent.
See http://www.jarfinder.com/index.php/java/info/org.eclipse.swt.SWTError
e.g. on Windows a suitable jar would be:
org.eclipse.swt.win32.win32.x86_3.1.0.jar
or on Mac OS X:
swt-macosx-3.0m7.jar
and so on.
You might run into call kinds of followup problems if you add this dependency e.g. whether you are
using 32bit or 64bit libraries.
It is too bad that these kind of dependency problems show up more often than not these days :-(
You have to set the classpath so that it includes at least the class org.eclipse.swt.SWTError
or the jar containing it:
java -classpath path/to/jar/containing/org.eclipse.swt.SWTError -jar five-server.jar
You should also set the Main-class attribute in the manifest file in the five-server.jar
Following the #Wolfgang Fahl answer, you might download the references here:
Standard Widget Toolkit » 4.3 x86
Maven reference:
https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86.4.3.swt/org.eclipse.swt.win32.win32.x86/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
Standard Widget Toolkit » 4.3 x64
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86_64.4.3.swt/org.eclipse.swt.win32.win32.x86_64/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar