0

I have a simple maven project where I have a simple class analyzing File encoding. I am using the juniversalchardet library from Google juniversalchardet library . In the pom.xml I added the dependency from link above. When I build the project with mvn clean install, everything looks fine. In the local repository I see tha universalchardet.jar file also. The class file in my project is also compiled without errors. But when I run my project .JAR i get an error like this:

Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/universalchardet/UniversalDetector

Here is my dependency:

    <dependency>
       <groupId>com.googlecode.juniversalchardet</groupId>
       <artifactId>juniversalchardet</artifactId>
       <version>1.0.3</version>
    </dependency> 

I am not very familiar with Java - what I am doing wrong?

digestBen
  • 77
  • 1
  • 11
  • 2
    How are you running the jar file? You have to make sure the library is in the classpath. – Jesper Jun 03 '20 at 10:04
  • When I look into the Java Build Path/Libraries/Maven Dependencies the file universalchardet.jar is listed there? You mean that or somehing else? – digestBen Jun 03 '20 at 10:09
  • If you just execute a jar on command line with something like `java -jar ...`, then this jar will no nothing about its Maven dependencies. – J Fabian Meier Jun 03 '20 at 10:31
  • I found the error! I didnt set the Classpath to the jar file in my bat file where I am executing the project .jar file. Maybe another question: I want the universalchardet.jar automatically place in the lib folder. Without manually copying it. How to configure that – digestBen Jun 03 '20 at 10:36
  • Does this answer your question? [Maven Run Project](https://stackoverflow.com/questions/1089285/maven-run-project) – Joe Jun 17 '20 at 14:04

1 Answers1

0

You can try this https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html where you mention your dependency jar in your manifest file : Class-Path: juniversalchardet.jar

Or Consider making your jar as uber jar, refer: What is an uber jar?

joy
  • 327
  • 4
  • 11