egordorichev / LastTry

:deciduous_tree: LastTry is open-source game written in Java, using LibGDX library and inspired by Terraria :deciduous_tree:
MIT License
119 stars 17 forks source link

No main manifest atrribute #27

Closed ryansnewell closed 7 years ago

ryansnewell commented 7 years ago

I have tried to build and run the project on both my Mac and Windows and have gotten the same errors on both computers. I followed the steps in the Readme and I can get "mvn package" to run. But after that I can't get anything to work.

target>java -jar lasttry-1.0.0-SNAPSHOT.jar no main manifest attribute, in lasttry-1.0.0-SNAPSHOT.jar

I have tried several variations of this including being in the target folder, out of it and using an absolute path, quotes, even trying to run the main class using the jar as the classpath:

target>java -cp lasttry-1.0.0-SNAPSHOT.jar org.egordorichev.lasttry.LastTry Error: Could not find or load main class org.egordorichev.lasttry.LastTry

The only warnings I get while running maven is that it's using platform encoding, could this be it? Where is the main manifest? Or how do I get it to generate properly?

egordorichev commented 7 years ago

Thank you! I will fix this today!

egordorichev commented 7 years ago

Added main class to the manifest. First part of issue is fixed, but the main class is still not found, don't know why.

ryansnewell commented 7 years ago

I tried adding a new class with a main method in the same package as LastTry.java and the new file was able to be run. In the new main file I called the main() method of LastTry and got the following:

Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/state/StateBasedGame
  at java.lang.ClassLoader.defineClass1(Native Method)
  ...
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at org.egordorichev.lasttry.Main.main(Main.java:6)

Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.state.StateBasedGame
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 13 more

So it seems like StateBasedGame cannot be found but not sure why it would build successfully if this was the case. I was able to solve this by using the maven shaded plugin which puts all the dependencies in the one jar, and then the new error is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
  at java.lang.Runtime.loadLibrary0(Runtime.java:870)
  at java.lang.System.loadLibrary(System.java:1122)
  at org.lwjgl.Sys$1.run(Sys.java:72)
  at java.security.AccessController.doPrivileged(Native Method)
  at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
  at org.lwjgl.Sys.loadLibrary(Sys.java:96)
  at org.lwjgl.Sys.<clinit>(Sys.java:117)
  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 org.egordorichev.lasttry.LastTry.main(LastTry.java:177)
  at org.egordorichev.lasttry.Main.main(Main.java:6)

Not sure why it compiles with dependencies but can't find them when I run it.

Col-E commented 7 years ago

Are the dependencies included in the built jar file? If not, are you adding them to the class path?

egordorichev commented 7 years ago

I think the maven file is completely broken. I will try to generate a new one.

egordorichev commented 7 years ago

Ok, i've figured out the first part of the error. The LastTry class, witch has the main() method, is extended from StateBasedGame. Moving main() to another class fixed it.

But now it looks like it doen't pack the dependencies right.

egordorichev commented 7 years ago

Sorry for this error, we are building using IDE and installed libs. Trying to figure out, why it does not pack the dependencies.

ryansnewell commented 7 years ago

Finally got it. Added "-Djava.library.path=lib/macosx/" to the command line when running and it worked.

egordorichev commented 7 years ago

Oh, great! Thank you! Will add that to the README.