beek
beek

Reputation: 3750

ClassNotFound - adding Third Party Jar to Maven

OK I'm new to this and struggling so please bear with me!

I'm attempting to add this to an existing web app

https://github.com/RusticiSoftware/TinCanJava

The instructions on the page suggest building the Jar with Maven which I've done. I've then tried several ways to get the compiled Jar into my web app project, for example

adding as a dependency

    <dependency>
        <groupId>tincan</groupId>
        <artifactId>tincan</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/tincan-1.1.1-SNAPSHOT-jar-with-dependencies.jar</systemPath>
    </dependency>

Or installing

mvn install:install-file -Dfile=C:\workspace\tincanJava\TinCanJava\target\tincan-1.1.1-SNAPSHOT-jar-with-dependencies.jar -DgroupId=com.rusticsoftware.tincan -DartifactId=tincan -Dversion=1.0 -Dpackaging=jar

I can see the files and classes in Intellij, all elements are showing, however when I run the application I get the following error:

Caused by: java.lang.ClassNotFoundException: com.rusticisoftware.tincan.StatementsQueryInterface
    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)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:509)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

Am I doing this wrong? Should I be adding the source to my directory and the dependencies to my POM and building that way?

Upvotes: 1

Views: 334

Answers (1)

Jens
Jens

Reputation: 69440

Scope system is the same as scope provided that means that this jar is not included in your dependencies. You have to add it to the classpath when running your application

From the documentation:

System

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

Provided

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive

Upvotes: 1

Related Questions