1

I know that there is a Git plugin for Eclipse ("Egit"), but I like to do Git stuff on the command line, and I like to code in Eclipse, so I want to keep them separate.

I cloned a Git repo (I don't think its important, but for good measure, it was https://github.com/spinscale/dropwizard-jobs.git). I then opened up Eclipse (Juno) and created a new Java project, and selected the root of the cloned repo as the base path to my project. Eclipse asked me if I wanted to associate the project with the Java facet, and I clicked 'OK'.

This project has a large dependency tree (if you like, check out its 4 POM files). I don't use Maven to build (I use Gradle) so I just ran a script that resolves the dependencies of these POMs into a directory, and then I created a lib directory in this Eclipse project and copied all the JARs into it. I then added all these JARs to the project's classpath.

I am now seeing 10 errors in the Problems view in Eclipse, and they're all similar errors:

  • The type ApplicationStartTestJob is already defined ApplicationStartTestJob.java /dropwizard-jobs/dropwizard-jobs-core/src/test/java/de/spinscale/dropwizard/jobs line 10 Java Problem
  • The type ApplicationStartTestJob is already defined ApplicationStartTestJob.java /dropwizard-jobs/dropwizard-jobs-guice/src/test/java/de/spinscale/dropwizard/jobs line 10 Java Problem
  • 8 more all like this, etc.

Sure enough, when I expand the entire project, I see it has the following structure:

dropwizard-jobs/
    dropwizard-jobs-core/
        src/test/java/
            de.spinscale.dropwizard.jobs
                ApplicationStartTestJob.java
    dropwizard-jobs-guice
        src/test/java/
            de.spinscale.dropwizard.jobs
                ApplicationStartTestJob.java
    dropwizard-jobs-spring
        src/test/java/
            de.spinscale.dropwizard.jobs
                ApplicationStartTestJob.java

So it seems that the maintainers of this project like to rename their unit tests with the exact same package/class names, and for some reason, Eclipse sees them as all belonging inside the same package. To test this I renamed dropwizard-jobs-core/src/main/java/de.spinscale.dropwizard.jobs.ApplicationStartTest to something else, and did the same for dropwizard-jobs-guice/src/main/java/de.spinscale.dropwizard.jobs.ApplicationStartTest and sure enough, all the errors associated with ApplicationStartTest being already defined went away.

So my suspicion is confirmed: The intention of these subfolders (dropwizard-jobs-core, dropwizard-jobs-guice and dropwizard-jobs-spring) is that they are sub-projects with separate classpaths. Eclipse thinks all of these source folders are part of the same project, and so it is lumping all of their classes into the same classpath. Since each subproject uses the same unit test naming conventions (same package/class names for each subproject), Eclipse see multiple classes in the same package as having the same name.

OK, good! I figured out the problem. But what's the solution? Ideally I would be able to keep all of these inside the same project, but perhaps modify the .classpath file or do something similar that instruct Eclipse to keep the subprojects separated from a classpath perspective. Any ideas?

DirtyMikeAndTheBoys
  • 1,077
  • 3
  • 15
  • 29
  • Why the downvote without an explanation? This is an [SSCCE](http://sscce.org), is not a dupe, and shows (fairly extensive) effort/research on my part. This is a valid question, IMHO, please reconsider the downvote and perhaps post a comment as to why you are not happy with the question. If your argumentation is logical/reasonable, I'll consider rephrasing the question or even removing it entirely! – DirtyMikeAndTheBoys Dec 24 '14 at 09:29
  • It's because this is off-topic. You're asking for help with your IDE, not with the program itself. While it's certainly related, I wouldn't go to a dentist for a broken jaw. Well, I would, because teeth would probably be broken as well, but you get the analogy. In addition, it's not an SSCCE that you gave, because there's no code, though other than that and being off-topic you are correct. – Nic Dec 26 '14 at 18:35

2 Answers2

1

SImply download eclipse m2e plugin, then import the project(considering you have already checked-out at your workstation), and do spend sometime learning MAVEN commands. here you can find an pverview of maven parent project and modules. Maven parent pom vs modules pom

Community
  • 1
  • 1
ppuskar
  • 773
  • 6
  • 9
0

One possible solution would be to introduce maven, which allows to naturally define a parent project and sub-projects in a multi-module maven project.
You can actually test that configuration outside of Eclipse, and then use M2Eclipse in order to import parent and its dependencies, at the same time (as commented in this answer) in your Eclipse.

Actually, the M2Eclipse project itself has guice test project, which you can use as model for your own guive subproject, in the repo sonatype/m2eclipse-guice, with an adequate pom.xml.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250