문제

Hello I am working on a project in Eclipse and am trying to export it so I can send it to some friends. I am clueless as to how to export so I watched some YouTube videos because that's all I could find on the topic. The video said to;

  1. File > Export
  2. Java > Runnable Jar
  3. Next
  4. Set the project launch config, export location, and library config. (I am using lwjgl and slick 2d) so I selected "Package required libraries into generated JAR".

Then I attempted to launch it on my desktop from double-click, nothing. Then I tried from command prompt with "java -jar my_jar_name.jar" and it threw this error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: 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.opengl.Display.<clinit>(Display.java:135)
        at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
        at javaGame.Game.main(Game.java:37)
        ... 5 more

Here is my main method in my project:

FYI: The first line is line #34 and the last is #43

public static void main(String[] args) {
    AppGameContainer appgc;
    try{
        appgc = new AppGameContainer(new Game(gamename));
        appgc.setDisplayMode(appgc.getScreenWidth(), appgc.getScreenHeight(), true);
        appgc.start();
    }catch(SlickException e){
        e.printStackTrace();
    }
}

If more info is needed please let me know!
P.S. This is the first Java project in Eclipse I have wanted to export so no I have not done it before.

도움이 되었습니까?

해결책 3

I figured it out after referencing another Stack Overflow question I just found moments ago. I used JarSplicer to create a Fat Jar that included the natives into my jar and it worked perfectly. I can now run my app by double clicking it and it runs just like in Eclipse, thank you for your support!

Exporting eclipse project to jar

다른 팁

Your problem is related to native libraries, when you are running the app the required library is not found. I am assuming you a have followed the instructions at

http://www.lwjgl.org/wiki/index.php?title=Setting_Up_LWJGL_with_Eclipse

to run your app you have to

java -Djava.library.path="<path to lwjgl native files>" -jar my_jar_name.jar

You may run your jar like this:

java -jar my_jar_name.jar main_class_name

main_class_name is the class name that contains your main method

You may also check if you have successfully created a jar with all the dependencies, here's how I add library jars:

Select the project, and perform the following steps:

Build Path -> Configure Build Path... -> Select Libraries tab -> Add External JARS

Alternatively, you may create a folder called lib, and put the jar in the lib directory, then you may perform the following steps:

Build Path -> Configure Build Path... -> Select Libraries tab -> Add JARS
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top