Denver
Denver

Reputation: 245

Issues with dependencies - Eclipse Java Project

I have a Java NLP project (say X) in eclipse which has dependencies in maven & also some jars added externally to buildpath.

Now I've built UI to this project(x) using java swing which is another project in eclipse (say Y).

When I run the project Y (which calls project X when a button is clicked) is throwing me errors like

java.lang.NoClassDefFoundError: edu/stanford/nlp/ie/NERClassifierCombiner

which I think is because, project Y is not able to find/recognize the external jar that I've added in project X.

I've tried adding all those external jars to Project Y's build path too but nothing worked.

Can you please help me figure out how to handle these dependency issues. Been struggling since 4 days.

Thank You.

Upvotes: 1

Views: 135

Answers (2)

Alekhya Vemavarapu
Alekhya Vemavarapu

Reputation: 1155

I faced similar issue. But I figured out that my problem was with maven dependencies but not with the external jar.
In my case, I did not create the main project (i.e. your Y) as a Maven project which was why it wasn't working. Moment I converted it (Y) to Maven project, my code started working like magic.

I just had to add the lib folder of project X in project Y too.

Hope this will solve your issue too.

Upvotes: 0

Abhishek Anand
Abhishek Anand

Reputation: 1992

You need to add external jars via maven first. I can think of three ways to do that.

  1. By adding the jars to a repository and accessing it. It can be even within your project like below, only thing is maven structure for jar needs to be followed.
<repository>
    <id>lib</id>
    <name>lib</name>
    <releases>
        <enabled>true</enabled>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <url>file://${project.basedir}/lib</url>
</repository>
  1. You can add jars to a lib folder, and add scope level system dependency, like,
<dependency>
     <groupId>myjar_1.0</groupId>
     <artifactId>myjar_1.0</artifactId>
     <scope>system</scope>
     <version>1.0</version>
     <systemPath>${basedir}\src\lib\myjar_1.0.jar</systemPath>
 </dependency>
  1. Install external jars to local repository via maven, and then add them as dependency, but, this method will make your build fail for any new system, where you check-out your code and try to build project.

Second and third method is highly discouraged to do though.

Also, consider making a fat jar using maven shade plugin, so that, all required jars are present into your jar already.

Upvotes: 1

Related Questions