0

I have 2 Projects namely Project_1 and Project_2. Both projects are Maven and I am using Netbeans.

I want to include the jar of Project_1 in Project_2 which I am doing like this.

The problem is when I include the jar I do not get any compile time error, however I get a NoClassDefFoundError exception at runtime.

When I include the Project_1 in Project_2 by performing the steps mentioned here. (The Open Project example). I do not get any errors. Neither runtime nor compile time.

Can you please explain me what am I missing here?

Update

Project_2 is deployed on a Server which is not in my local machine however Project_1 is in my local machine.

Inclusion of Project_1 into Project_2 as a project was done for testing in my local machine.

Community
  • 1
  • 1
JHS
  • 7,761
  • 2
  • 29
  • 53

1 Answers1

0

First of all, a good rule of thumb to adopt is never use the system scope and system path to pull in dependencies. In my experience there's always a better way :-)

If Project_2 depends on Project_1, then first install it's jar into the local repository:

   cd Project_1
   mvn clean install

Watch the output you'll discover the jar is placed somewhere under the following directory:

   $HOME/.m2/repository

Once this is done the jar will be available as a normal dependency to the second build

  cd Project_2
  mvn clean compile

The local repository ensures the projects are now decoupled from each other. Assuming you're using snapshot revisions of Project_1, the Project_2 build will always retrieve the latest revision built and tested.

Update

You should use a Maven repository manager to share jars between machines/teams. Recommendations are contained in the following answer:

Share jar of the module with another team

How to configure Maven to use a repository like Nexus is described in it's documentation.

As described in the deploy plugin documentation you'll need to add a distributionManagement section to your POM (detailing the repository URL) and then upload the project's jar to your repository as follows:

   cd Project_1
   mvn clean deploy
Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Thank you however there is issue. The `Project_1` is a project in my local computer and `Project_2` is a project deployed in a server. To include `Project_1`'s jar in `Project_2` i have to place the `Project_1`'s jar somewhere in the server and include it in `Project_2`. – JHS Jun 05 '12 at 21:19
  • @Juniad Then you need to install a Maven repository manager and use this to deploy build output and pull dependencies. Highly recommended when you're sharing jars and will also improve the performance of your builds. See http://stackoverflow.com/questions/9201195/share-jar-of-the-module-with-another-team/9202409#9202409 – Mark O'Connor Jun 05 '12 at 21:47