0

I am new to Maven Project. I am making changes to one of the open source maven project. I am facing a problem in adding a library to the project. So far i have done this :-

  1. I added a library named jni4net.j-0.8.8.0.jar to the resources folder of the project.
  2. I right clicked the jar(in Intellij) and clicked 'Add as library'.
  3. Then in the pom.xml i added:-

    <dependency>
        <groupId>jar.0.8.8.0.jni4net</groupId>
        <artifactId>jar.0.8.8.0.jni4net</artifactId>
        <version>0.8.8.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/src/main/resources/jni4net.j-
         0.8.8.0.jar</systemPath>
    </dependency>
    

But when i build this project(build is successful, test cases are running) and use this it throws following error:-

java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge 

Please help me resolve it. I am new to maven and pom. I have looked at various answers, but not getting it right. PS - I named groupId and artifactID as just reverse of jar file

DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
Shubham Gupta
  • 159
  • 1
  • 14
  • At what point exactly does this happen. You say that build is successful but when you "use this" it happens. What does that mean, during the build somewhere or when you try to run it? – DanielBarbarian Jun 13 '17 at 05:51
  • The code i am referring to is a Teamcity plugin code. Locally the build is successful. I then pick the compiled zip from target folder and place it to the plugins folder in TeamCiy directory from where it reflects in plugins list of teamcity. I then make use of this plugin. – Shubham Gupta Jun 13 '17 at 06:17

2 Answers2

1

This is not the right way to add that dependency.

All you need is:

<dependency>
    <groupId>net.sf.jni4net</groupId>
    <artifactId>jni4net.j</artifactId>
    <version>0.8.8.0</version>
</dependency>

The dependency will be retrieved from Maven Central when you build.

Using <systemPath>...</systemPath> is highly discouraged as it usually ties your project to a local environment.

Steve C
  • 18,876
  • 5
  • 34
  • 37
  • I removed the jar files locally present, updated the pom with above dependency, but now import net.sf.jni4net.*; is showing - can't resolvejni4net – Shubham Gupta Jun 13 '17 at 07:10
  • This is often resolved by performing an initial command line build. Sometimes Intellij Idea fails to download remote dependencies. – Steve C Jun 13 '17 at 08:40
  • dependencies are downloaded when i ran 'mvn clean install' and commented out all the uses of this library. But intelliJ starts showing error while writing- import net.sf.jni4net.*; This is pathetic. – Shubham Gupta Jun 13 '17 at 11:07
0

Since jni4net.j dependency is available in maven central, You don't have to download and put the dependency manually. Maven will download and store the dependency locally in `'.m2' folder. Just add dependency as bellow.

<dependency>
   <groupId>net.sf.jni4net</groupId>
   <artifactId>jni4net.j</artifactId>
   <version>0.8.8.0</version>
</dependency>
rnavagamuwa
  • 310
  • 2
  • 11
  • I removed the jar files locally present, updated the pom with above dependency, but now import net.sf.jni4net.*; is showing - can't resolvejni4net – Shubham Gupta Jun 13 '17 at 07:10
  • Since you are using intelliJ Idea to run the project, [reload the project dependencies using idea](https://stackoverflow.com/questions/9980869/force-intellij-idea-to-reread-all-maven-dependencies). If that doesn't work, check weather the project builds(`mvn clean install`) properly without giving any errors. – rnavagamuwa Jun 13 '17 at 07:22
  • Thing is as soon as i remove systemPath, the mvn clean install fails - compilation error, and as soon as i replace it back, it works agan. Though the package has been downloaded into my .m2(i guess local maven directory) – Shubham Gupta Jun 13 '17 at 10:21
  • Are you using idea to build the project? Though it's not necessary make sure you have turned **work offline** in idea. – rnavagamuwa Jun 13 '17 at 16:30