Project build to jar can not run

ysx3 years ago

Hi,i have a problem in this project.
I use gradlew assemble to build a jar in the build floder.
But when i use java -jar tracker-server.jar,terminal display Error: A JNI error has occurred, please check your installation and try again.(Project can be run locally)
Could you give me some help?
Thanks.

Anton Tananaev3 years ago

You need to check full exception stack.

I would also recommend trying different Java version.

ysx3 years ago
shellError: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Injector
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Injector
        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)
        ... 7 more

This is the exception log.
You mean this is the reason for jdk version?

Anton Tananaev3 years ago

Looks like you are missing some third party libraries or you are using wrong versions of dependencies.

ysx3 years ago

But i can run nomally locally...

ysx3 years ago

I use your project to build without changing anything,it also display the same error...
Is there something wrong with my packing method?

Miko Bonzo3 years ago

Kindly do check your Classpath setting on your MANIFESTwhen you compile the jar file

Carlos Colque3 years ago

hi,
did you fix your problem, I think that I have the same problem, I have builded the tracker-server.jar but when I replace the file, the server can't start, I don't know where could I see some log for to show it. I check with java version 1.8 and 11, the command that I use is "./gradlew assemble".
thank you for your answer.
regards.

Anton Tananaev3 years ago

You don't know where to find logs? Where did you replace the file?

Miko Bonzo3 years ago

Hi. What file are you replacing ?

Carlos Colque3 years ago

Hi,
I just know the tracker-server.log, but the de only register is shutdown server, when I try start the server I don’t see any new record.
My procedure is:

  1. Build the tracker-server.jar
  2. In server, shutdown with this command “ sudo systemctl stop traccar.service”.
  3. Chamge the name of actual tracker-server.jar in the root of traccar folder like a backup.
  4. To transfer the new file tracker-server.jar to server.
  5. Start the service with “ sudo systemctl start traccar.service”.

That was my procedure.

Thanks

Miko Bonzo3 years ago

Hi. Can you build using this way.

./gradlew build -x checkstyleMain

Anton Tananaev3 years ago

Miko Bonzo, how would that solve the problem?

Carlos Colque, did you build the correct version? What error do you get if you run Traccar manually from the command line?

Carlos Colque3 years ago

Hi.
I did the manually start, it show me the next message:
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Injector at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632) Caused by: java.lang.ClassNotFoundException: com.google.inject.Injector at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 7 more

Anton Tananaev3 years ago

It means that you haven't compiled the correct version.