0

I am using https://github.com/patternconsulting/opencv to include opencv 3.2.0 in my maven java project.

The issue that I am facing is that when i use mvn install to generate a jar file and then run the jar file java -jar app.jar i get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: nu/pattern/OpenCV
    at com.example.Application.<clinit>(Application.java:21)
Caused by: java.lang.ClassNotFoundException: nu.pattern.OpenCV
    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)

below is an extract of my pom.xml file

       <dependency>
            <groupId>org.openpnp</groupId>
            <artifactId>opencv</artifactId>
            <version>3.2.0-1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <mainClass>com.example.Application</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

and below is an extract of my class that has the main method:

public class Application {

    static {
        OpenCV.loadShared();
    }


    public Application() throws Exception {
      // some code here
    }

    public static void main(String[] args) {
            new Application();
    }

any idea what might be causing this to happen and how to solve it?

Thanks

1 Answer 1

1

Dependencies are not automatically added to your jar file, only your own code.

You have several options because you are not the first to have this problem. At your current skill level I would suggest looking into creating an uber-jar instead (so all your dependencies go in your jar file too).

Have a look at https://stackoverflow.com/a/1834905/53897 which details how to go from here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.