Tuesday, March 15, 2011

Developing PicoContainer 3.0 in Eclipse with the Maven Plugin

 

Problem

When you first import the PicoContainer project into the Eclipse IDE, the base project will compile fine, but any additional project will contain the error:
“The project was not built because its build path is incomplete.  Cannot find the class file for com.googlecode.jtype.Generic.
You might also see a similar message refering to a class in: javax.inject.* or com.thoughtworks.paranamer.*
However, if you drop to the console and try to build it manually, everything works peachy.
What’s going on?

Explanation:

To keep 3rd party dependencies to a minimum, PicoContainer’s core build process uses the maven-shade-plugin to wire in a couple of utility jars in picocontainer.jar.  That’s all fine and dandy, but Eclipse doesn’t understand what’s going on in the build processes and complains.
There are three jars that are getting shaded that Eclipse isn’t finding:
<dependency>
    <groupId>com.thoughtworks.paranamer</groupId>
    <artifactId>paranamer</artifactId>
</dependency>
<dependency>
     <groupId>javax.inject</groupId>
     <artifactId>javax.inject</artifactId>
     <version>1</version>
</dependency>
<dependency>
    <groupId>com.googlecode.jtype</groupId>
    <artifactId>jtype</artifactId>
     <version>0.1.1</version>
</dependency>

 


Solution:


Manually add the jar files to your build path in Eclipse and everything will work fine. 

To do this:

  1. Right click on the project, Select Properties
  2. Click on Java Build Path
  3. Click on the Libraries tab.
  4. Click on Add External Jar
  5. Repeat adding external jar until you’ve added all three jars into your project.
Hint: The jars can be located in ${userhome}/.m2/repository since Maven will have automatically downloaded them for you.
When you use Maven to create final artifacts, Maven will behave appropriately shade in the three jars into picocontainer.jar, and all applications will behave as if those jars are appropriately in the classpath.

No comments:

Post a Comment