1

I have a simple program that parse csv file into json objects. I added json.simple-1.1 into my maven. The content of my maven is like this:

    <groupId>IoT</groupId>
    <artifactId>ETL2</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
    </dependencies>



    <build>
        <plugins>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>ETL2</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build> 

I try to execute the jar artifact in the terminal. I get these errors.

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException 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:544) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) > Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more

I read in here that

This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.

That's why I suspect that my maven configuration might not be correct.

  • I have checked the artifact and and confirm, class is available in the package. checked at [maven jar lib](https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1)], maybe try to do standard `maven clean, maven install, maven compile` if helps. Or you can try to link lib manually as external lib dependecy through IDE, to test if that will works.. Except this don´t have more idea. But maybe that helps :) ( `-X` should work for debug info) – xxxvodnikxxx Mar 09 '18 at 09:44

1 Answers1

2

Change your plugin to the below snippet and it is highly recommended you read How to build an executable jar with dependencies

<build>
    <plugins>
        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>ETL2</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build> 
  • I tried your snippet. The descriptorRef rag is shown in red. It is now allowed to use it in here. – Farhood Hosseinpour Mar 09 '18 at 12:40
  • @FarhoodHosseinpour i don't know what you're using or why it's in red. but it's perfect in my version of eclipse. in both version 3.0.2 and also 3.6 which my spring boot uses. –  Mar 09 '18 at 13:05