Can't find or load main class JarSplice - java

Hello fellow programmers! I am writing a game at the moment, that uses the following libraries: LWJGL, OpenGL, Slick. I know the problems with simply exporting a JAR file from eclipse when using libraries like that, and I do use the JarSplice program to make a fat JAR. This has worked fine for about a month now, however, just recently it stopped working. Whenever I export the JAR from eclipse, and make it a fat JAR using JarSplice, I get this error:
Could not find or load main class Game.jar
META-INF (Located in the fat JAR):
Manifest-Version: 1.0
Launcher-VM-Args:
Launcher-Main-Class: cubix.main.Cubix
Main-Class: org.ninjacave.jarsplice.JarSpliceLauncher
Please note that the main method of the program is located in the Cubix.class, which is located in cubix.main.Cubix'
I have never came across this error before, and it is driving me insane. If any additional information is required, please feel free to ask.
EDIT:
I might also add that if I export any other project this way (using the same libraries and using jarsplice to build a fat JAR) it works just fine. I am only experiencing this problem with this specific project in eclipse. However, when I run Cubix in eclipse debugger, it runs just fine.

Try couple of things :1 check the content of the file, use jar -tf see everything is present2. can you try running this file from command/terminal.3 if all above is good, compile Cubix.java from terminal and place this .class file in jar file manually and check.

I'm sorry for posting this. The problem wasn't that it couldn't find the main class but rather I had typed the command line wrong. I typed: 'java Cubix.jar -jar' rather than 'java -jar Cubix.jar'. Also, after fixing the command line, it gave me the stack trace for the error that was overlooked by eclipse, and that one of the textures that needed to be loaded was case sensitive.

Related

Missing library on java.library.path trying to deploy executable JAR

I'm attempting to execute an executable JAR I generated using Eclipse for a Slick2D game project I'm trying to deploy, and I keep getting an error saying:
java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path
I followed the Slick2D setup to the letter when setting up the project months ago. But up until now, I've always run through Eclipse, and have never attempted to run through a JAR.
To generate the JAR, I chose Export -> Runnable JAR, and I chose to package the required libraries into the JAR. I then tried to execute the JAR from the command line as so:
java -jar JAR_NAME.jar
After receiving the above error, I tried many different methods of getting this so-called lwjgl64 library onto the java.library.path, but to no avail.
So far I've tried:
Changing the native library location of lwjgl.jar in my Slick2D user library to the folder containing the lwjgl-natives-*.jar files, but those only have the 32-bit definitions in them, and I figured it was looking for a DLL, so...
I ran the following command instead:
java -jar JAR_NAME.jar -Djava.library.path="C:\slick2d"
But this produced the same result, even though that directory contains lwjgl64.dll, among other files.
I tried copying all of the dll/so files from C:\slick2d into a folder called natives in a source folder in Eclipse and using the following code to set it as the java.library.path:
System.setProperty("java.library.path", "libs");
System.setProperty("org.lwjgl.librarypath", new File("libs/natives").getAbsolutePath());
But this just resulted in yet another error:
java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\packetpirate\workspace\GZS Redux\target\libs\natives\lwjgl64.dll
Does anyone have any insight into this problem? I'm not great at building projects, especially in Eclipse, so I've always had trouble with linking dependencies. I've thought of converting my project to Maven, but I wouldn't know where to start and how to set it up.
EDIT: I realized that the libs/natives folder was not copied to the target folder when I generated my JAR, and after copying it over, I was able to run the JAR, but I still get similar errors related to jinput-dx8_64 and jinput-raw_64, which are also in the same folder. It doesn't seem to affect the game's behavior, though...
Also, although I know this is a Slick2D specific thing... it seems to be loading my assets twice. The only way I can see this happening is if the Loading state is entered twice, which doesn't make sense.

Program runs in Eclipse, but exported runnable jar file will not open?

It looks like this is a common problem, but none of the previous posts seem to address my issue.
I believe I've narrowed it down to one problem. Any application that uses an InputStream will not open, but all my other applications run fine.
The application runs fine in Eclipse, but the window won't even open when I try to run the jar file.
Task manager shows it pop up for about a second or two, and then disappears.
I have tried all three options for the Library handling upon exporting and none of them fix the issue.
Can anyone explain this?
Run it from the command line. This will allow you to see the exception that's thrown that's preventing your program from progressing.
java -jar YourJar.jar
I know I'm late, but I want to prevent people having to search hours for the same Error I just did. In Eclipse the path-String isn't case-sensitive. In the exported Runnable Jar File it is. So make sure all the pathsnames have the capital letters in the right positions, or to be save don't have capital letters at all.
Setup Your Manifest
If I had to guess, your manifest doesn't contain your main class OR the classpath is not defined.
Main-Class: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Class-Path: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
If you're using a build tool like maven, it needs to be configured to add these properties: https://maven.apache.org/shared/maven-archiver/examples/classpath.html
Execute Your Jar
There are two ways to run an executable jar. As an executable jar you need to define the Main-Class and Class-Path in your manifest:
java -jar YourJar.jar
You can also skip setting up your manifest and define your classpath and main class through the JVM's parameters.
java -cp=${PATH_TO_JAR} main.package.MainClass

Java Program only runs in IDE, not exported as a Jar

I can run my software without any problems in my IDE, but when I try to compile it to a jar, and try to run it, it says that the main class can't be found. I succeeded to make it work perfectly several times in the past, but I found this problem few time ago, so I can't really know when it went wrong.
The jar has a META-INF, all properly set up, like in my older versions, and the main class is there. Other peoples can't compile too, so it's not just me. The code is on Github, so that could be a tool to help me solve this.
But I want to know, just by reading this, is there some common mistakes that could cause this, or this is uncommon?
EDIT:
I'm using IntelliJ IDEA
and I will check if the versions are the same.
EDIT2:
They do have the same version, and it's exporting an executable jar with the correct main class defined, as I have beeing doing for all the previous versions.
Check that the MANIFEST.MF is present in the META-INF folder of the jar, and make sure that the line :
Main-Class: yourMainClass
is present inside the file, then make sure that you start the jar with this command line :
java -jar yourjar.jar
Have you tried to launch the jar file specifying the main class ? For example :
java yourjar.jar yourMainClass
Does it work in this way ?

Exporting an Eclipse Project into a Runnable Jar does not work

I'm trying to export my java application to a Runnable Jar file.
This worked before, but apparently I've tinkered with something and now it doesn't work.
Exporting from Eclipse works without problems, but when I'm starting the .jar an error shows up:
"Could not find the main class: game.Main. Program will exit."
Now, the game.Main class is my main class so that's ok.
When I run the .jar via command line like this:
java -cp D:\PathToMyJar\test.jar game.Main
It also works just fine.
I just can't run the .jar file itself.
The Run Configuration with which I'm exporting is set to the correct Project and main class.
I hardly used Eclipse's export features before, so I'm kinda out of options I could think of.
From what I've read it might be some problem with the manifest file, but I don't know where to check it or how to change it - apart from the fact that Eclipse should be able to do that on it's own somehow ...
PS: The manifest inside the jar file looks like this:
Manifest-Version: 1.0
Class-Path: .
Main-Class: game.Main
Main-Class is correct. I don't know what Class-Path generally is, but I guess that means wildcard, so OK too.
Make sure the jar contains manifest file with correctly specified main class.
Follow these instructions: http://www.skylit.com/javamethods/faqs/createjar.html

Deploying a Java application. How?

I am new to Java (and Eclipse) but I have used .NET (and Visual Studio) a fair amount. I also know about compiling C/C++ code and things like that. I know that at the end I get either an EXE or a nice binary file that can be run from the command line.
I have been making a Java utility that uses some external libraries. I need to compile this into an executable that I can run from the command line on a unix machine, but I cannot find any way to do this.
I can build and run/debug in Eclipse, but that is no use to me as this code will be run on a webserver. I just need all the dependancies compiled in to one file but after hours of searching on Google, the best thing I could find was the Fat-JAR plugin for Eclipse and after using that I just get the following error when I try to run the file:
Exception in thread "main" java.lang.NoClassDefFoundError: Network/jar
This is really confusing me and as it is such an essential thing to be able to do I am sure I must be missing something blindingly obvious, but as I said, after hours of searching I have gotten nowhere.
I really appreciate any help you can give me. Thanks.
If you build your java app using Maven (which can be done with every major IDE), then you can use the maven Shade Plugin to build a shaded jar file; this is a jar file with all of its dependencies included.
A shaded jar can be run from the command line like this:
java -jar myjar.jar command line options
You're doing something standard and you're using eclipse. This means, in your case, Maven is your friend. Download and install the M2Eclipse plug-in. Maven is best at managing dependencies. So, creating a jar with dependencies included will be very, very straight forward. There are thousands of examples on the web and in StackOverflow. If you have problems setting it up, comment on this and I can point you in the right direction.
Sounds like your class path on the server needs to be modified to pick up the jar file containing the Network class. How are you executing your program? What path(s) are you putting in the -cp option?
If you are not sure how to find out the contents inside a jar file, run jar tf , this will list the packaged classes. Validate that one of the jars in your CLASSPATH has that class it says missing.
Give us more details and we can help solve it.
I think I should first explain some basics. A Java class can be run as an application if it has a public static void main(String[] args) method. If it has this method, you can run it from command line as:
java my.package.MyClass <attributes>
Before launching your app, you need to make sure that all required .jar files (and the root of your own class folders, if you did not make a jar from your classes) are in the CLASSPATH environment variable.
These are the absolute basics. When you are building a more complex app, or an app for distribution, you'll probably use maven or ant or some other tool that makes your life easier.

Categories

Resources