Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new to maven environment, need some ones help. Added my external jar file (directoryhelper.jar) in lib folder as below in pom.xml

<dependency>
      <groupId>com.test.directoryhelper</groupId>
      <artifactId>DirectoryHelper</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/directoryhelper.jar</systemPath>      
</dependency>

compilation is successful, but during run time I am getting java.lang.NoClassDefFoundError.

how to add the directoryhelper.jar to class path.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
927 views
Welcome To Ask or Share your Answers For Others

1 Answer

Maven out of the box will come up with a JAR file (default packaging). This JAR file only contains (main) artifacts of the project. If you take just that and run it, clearly the dependencies are missing -- by design.

Typically Maven artifacts are reused in combination with their POM so that at the point of use it's know what the dependencies are. Edit: if you're using APKs and installing them on a phone, there may be mechanisms to deal with dependencies, I'm answering this merely from a Maven standpoint.

If you want to create a JAR with dependencies you have to tell Maven to do so, that's not the default. Ways of having Maven do that are (probably not exhaustive):

  • Maven Assembly plugin, jar-with-dependencies predefined descriptor:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    ...
    
  • Maven Shade plugin


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...