luk
luk

Reputation: 5

maven and eclipse - dependency on my project

I have 2 projects: MyApp and MyUtis.

I want to add MyUtils as a dependency to MyApp. It almost works. I can build MyAppl with a dependency on MyUtils and a create jar file. It is OK from the command line.

But I have a problem with eclipse. I have a compiled MyUtils jar file is in my local maven repository but MyApp project in eclipse do not see MyUtils when I don't have MyUtils in the same workspace and in eclipse. When I add MyUtils project into my eclipse workspace, the project must be opened in eclipse, I can see MyUtils classes from MyAppl.

Can you help me? Is it possible add a dependency onto MyAppl without adding MyUtils project into same workspace?

In MyAppl project I do not see jar file of MyUtils in "Referenced Libraries" in eclipse.

Thanks.

Upvotes: 0

Views: 202

Answers (2)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

@Behe's answer is completely reasonable, but there is another solution if you don't want to add a new plugin to Eclipse. You can run on the command line:

mvn eclipse:eclipse

two issues though:

  1. You must re-run this every time MyApp changes its dependencies
  2. Every time MyUtils changes (anything at all), you must re-install to your local maven repo.

This is kind of a pain, but if MyUtils doesn't change much and MyApp doesnb't have its classpath change often, this might be a better solution than m2eclipse.

Upvotes: 0

Behe
Behe

Reputation: 7950

Without a maven plugin, Eclipse does not know where to find your libraries. I would recommend installing m2e. Eclipse 4.2 Java (not Java EE) has it already installed. Then, eclipse is able to resolve your .jar dependency.

Note that you have to install the MyUtils.jar so that the jar is available in your local repository or you have to deploy it in a repository like Nexus or Artifactory.

(You could also just add the jar to the build path, but then you would have to manage two dependencies, one within the pom.xml and one in your Eclipse project.)

Upvotes: 0

Related Questions