views:

60

answers:

2

I have two source trees in my Java application in Eclipse. One is "src", and one is "test". Each one contains a directory tree of .java files. So far, so good.

However, I would like the classes in "test" to be able to see the classes in "src", but for the classes in "src" to not be able to see the classes in "test". Similarly, I want to include some test libraries. I don't want any of those libraries to be available in the "main" tree, lest I accidentally use one without thinking.

Is there an easy way to set this up in Eclipse?

+5  A: 

There is no way to solve this in Eclipse without splitting the two source trees into separate projects (with one depending on the other). Maven could handle that at build time though.

Pascal Thivent
+1 for maven. makes life a lot easier.
Jeff Storey
Are there any disadvantages to the "separate projects" solution?
MatrixFrog
Yep, I've used Maven for this previously. The Maven plugin for Eclipse is very good about blocking the right jars from the right trees. For this project, though, I'm not using Maven, and I was hoping there was an easy way.Guess there's no downside to a separate test project. Will try that.
CaptainAwesomePants
@MatrixFrog Maybe at the SCM level (you may forget to commit changes in different projects in an atomic way). Also, I don't think it simplifies things. But I guess it's an acceptable solution if you don't have dozen of modules.
Pascal Thivent
+1  A: 

You don't need separate projects if you use IntelliJ. You just specify application and test packages. It's possible to mark libraries as part of application and test as well.

Eclipse ought to have equivalent buried under all those plugins. If not, IntelliJ has a community edition now.

Or just use Ant. Personally, I prefer it to Maven. I find Maven to be too complex for such a simple job.

duffymo
With all due respect, *"I find Maven to be too complex for such a simple job."* is just wrong. Having separate tree and class paths for code and tests is a native feature in Maven, there is nothing to do. You can't bean Maven on that with Ant.
Pascal Thivent
Maven is too complex in general, in my view. With all due respect, I'd rather just use IntelliJ for myself and Ant when I need to do continuous integration. Maven is irrelevant to me.
duffymo
As you wish of course :) But for this particular need, the Ant way *is* more complex, which was my initial concern.
Pascal Thivent
`%s/bean/beat/g` in my initial comment.
Pascal Thivent
I've had separate application and test classpaths in Ant. I don't think it's complex at all. Just my opinion, of course. I hold yours in great esteem. And the open source world agrees with you, because I see Maven everywhere. I'm just behind, I guess. 8)
duffymo
I'm not saying you can't do it, I'm saying it's simpler with Maven. With this http://pastebin.com/f45cfb494, you can compile, test, package, install (and create a minimal site)! Writing something equivalent with Ant can't be simpler.
Pascal Thivent