Traccar 4.5 Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

roneskinder 6 years ago

Im having an issue starting the service after a successful compile from ./gradlew build

    Rons-iMac:AutoSmart_Traccar_4_5 roneskinder$ ./gradlew build

    BUILD SUCCESSFUL in 1s
    7 actionable tasks: 1 executed, 6 up-to-date
    Rons-iMac:AutoSmart_Traccar_4_5 roneskinder$ scp target/tracker-server.jar root@162.241.45.13:/opt/traccar/
    root@162.241.45.13's password: 
    tracker-server.jar                           100% 1444KB 287.8KB/s   00:05

    xavliamy@server.xav.lia.mybluehost.me [traccar]# sudo service traccar start
    Redirecting to /bin/systemctl start traccar.service
    xavliamy@server.xav.lia.mybluehost.me [traccar]# sudo service traccar status
    Redirecting to /bin/systemctl status traccar.service
    ● traccar.service - traccar
        Loaded: loaded (/etc/systemd/system/traccar.service; enabled; vendor preset: disabled)
        Active: failed (Result: exit-code) since Thu 2019-11-07 09:38:54 MST; 5s ago
       Process: 19039 ExecStart=/opt/traccar/jre/bin/java -jar tracker-server.jar conf/traccar.xml (code=exited, status=1/FAILURE)
      Main PID: 19039 (code=exited, status=1/FAILURE)

    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: at org.traccar.Main.<clinit>(Main.java:35)
    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    Nov 07 09:38:54 server.xav.lia.mybluehost.me traccar[19039]: ... 1 more
    Nov 07 09:38:54 server.xav.lia.mybluehost.me systemd[1]: traccar.service: main process exited, code=exited, status=1/FAILURE
    Nov 07 09:38:54 server.xav.lia.mybluehost.me systemd[1]: Unit traccar.service entered failed state.
    Nov 07 09:38:54 server.xav.lia.mybluehost.me systemd[1]: traccar.service failed.

I also tried compiling from Maven mvn package and it builds ok but exactly same error, i dont know what is going on, any ideas?

Thanks

Anton Tananaev 6 years ago

My guess is that you forgot to copy dependencies and you are using incompatible versions.

roneskinder 6 years ago

Im using intelliJ, the mvn package command does a dependencies copy in the log [INFO] --- maven-dependency-plugin:3.1.1:copy-dependencies (default) @ traccar --- and it says that dependencies already exists in destination and i have a folder named dependencies in the project, so im not sure what am i missing?

Here is the complete log:

Rons-iMac:AutoSmart_Traccar roneskinder$ mvn package
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< org.traccar:traccar >-------------------------
[INFO] Building traccar 4.5-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-checkstyle-plugin:3.0.0:check (checkstyle) @ traccar ---
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-bytecode-version) @ traccar ---
[WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53
[WARNING] Invalid bytecodeVersion for module-info.class: expected 52, but was 53
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ traccar ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/roneskinder/Documents/Development/AutoSmart_Traccar/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ traccar ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ traccar ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/roneskinder/Documents/Development/AutoSmart_Traccar/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ traccar ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ traccar ---
[INFO] Surefire report directory: /Users/roneskinder/Documents/Development/AutoSmart_Traccar/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.traccar.WebDataHandlerTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.294 sec
Running org.traccar.handler.FilterHandlerTest
Nov 07, 2019 11:35:00 AM org.traccar.handler.FilterHandler filter
...
Tests run: 9, Failures: 0, Errors: 0, Skipped: 9, Time elapsed: 0 sec
Running org.traccar.reports.ReportUtilsTest
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.017 sec

Results :

Tests run: 383, Failures: 0, Errors: 0, Skipped: 16

[INFO] 
[INFO] --- maven-jar-plugin:3.1.1:jar (default-jar) @ traccar ---
[INFO] Building jar: /Users/roneskinder/Documents/Development/AutoSmart_Traccar/target/tracker-server.jar
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.1:copy-dependencies (default) @ traccar ---
[INFO] org.liquibase:liquibase-core:jar:3.6.3 already exists in destination.
[INFO] org.eclipse.jetty:jetty-jndi:jar:9.4.18.v20190429 already exists in destination.
...
[INFO] com.fasterxml.jackson.core:jackson-annotations:jar:2.9.8 already exists in destination.
[INFO] commons-validator:commons-validator:jar:1.3.1 already exists in destination.
[INFO] com.sun.xml.bind:jaxb-core:jar:2.3.0.1 already exists in destination.
[INFO] com.github.jnr:jnr-x86asm:jar:1.0.2 already exists in destination.
[INFO] com.fasterxml.jackson.datatype:jackson-datatype-jsr353:jar:2.9.8 already exists in destination.
[INFO] org.apache.velocity:velocity:jar:1.7 already exists in destination.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.125 s
[INFO] Finished at: 2019-11-07T11:35:03-06:00
[INFO] ------------------------------------------------------------------------
Anton Tananaev 6 years ago

Have you scp those dependencies?

roneskinder 6 years ago

Yes i did copy the dependencies folder to /opt/traccar/

xavliamy@server.xav.lia.mybluehost.me [traccar]# ls -l
total 4220
drwxr-xr-x 2 root root    4096 Sep 19 11:04 conf
drwxr-xr-x 2 root root    4096 Jul  3 12:32 data
drwxr-xr-x 2 root root   12288 Nov  7 11:51 dependencies
drwxr-xr-x 7 root root    4096 Jul  3 12:32 jre
drwxr-xr-x 2 root root   12288 Jul  3 12:32 lib
drwxr-xr-x 2 root root   12288 Nov  7 00:00 logs
drwxr-xr-x 2 root root    4096 Nov  1 18:48 schema
drwxr-xr-x 5 root root    4096 Jul  3 12:32 templates
-rw-r--r-- 1 root root 1433029 Nov  7 11:51 tracker-server.jar
-rw-r--r-- 1 root root 1416272 Jul 16 10:41 tracker-server.jar.06_11_19
-rw-r--r-- 1 root root 1407063 Jul  3 12:32 tracker-server.jar.original
drwxr-xr-x 6 root root    4096 Jul  3 13:10 web
xavliamy@server.xav.lia.mybluehost.me [traccar]# sudo service traccar restart
Redirecting to /bin/systemctl restart traccar.service
xavliamy@server.xav.lia.mybluehost.me [traccar]# sudo service traccar status
Redirecting to /bin/systemctl status traccar.service
● traccar.service - traccar
   Loaded: loaded (/etc/systemd/system/traccar.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2019-11-07 11:51:45 MST; 6s ago
  Process: 26048 ExecStart=/opt/traccar/jre/bin/java -jar tracker-server.jar conf/traccar.xml (code=exited, status=1/FAILURE)
 Main PID: 26048 (code=exited, status=1/FAILURE)

Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: at org.traccar.Main.<clinit>(Main.java:35)
Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Nov 07 11:51:45 server.xav.lia.mybluehost.me traccar[26048]: ... 1 more
Nov 07 11:51:45 server.xav.lia.mybluehost.me systemd[1]: traccar.service: main process exited, code=exited, status=1/FAILURE
Nov 07 11:51:45 server.xav.lia.mybluehost.me systemd[1]: Unit traccar.service entered failed state.
Nov 07 11:51:45 server.xav.lia.mybluehost.me systemd[1]: traccar.service failed.
Anton Tananaev 6 years ago

Well, that's not what I see in your original comment, which clearly shows that you only copied a single JAR file.

roneskinder 6 years ago

yes, i copied the folder sorry i did not show it here, any ideas on how to proceed? this is very weird

roneskinder 6 years ago

So i made it work, but im not sure its the proper way, i compiled the maven profile "jar-with-dependencies", which generated a file tracker-server-jar-with-dependencies.jar then i did sudo mv tracker-server-jar-with-dependencies.jar tracker-server.jar and sudo service traccar start and it worked, and took my changes

sudo service traccar status
Redirecting to /bin/systemctl status traccar.service
● traccar.service - traccar
   Loaded: loaded (/etc/systemd/system/traccar.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-11-07 12:06:04 MST; 5s ago
 Main PID: 26781 (java)
   CGroup: /system.slice/traccar.service
           └─26781 /opt/traccar/jre/bin/java -jar tracker-server.jar conf/traccar.xml