1

Is there a way to create 2 source folder in a single java project in eclipse, that will be isolated from each other, meaning it will not be possible in source folder 1 to use code from source folder 2?

Thanks

2
  • 1
    Hi, I don't think this is possible as all resources from buildpath are shared among the project's source. You'd prefer to play with classes' visibility. Commented Mar 1, 2011 at 9:16
  • Unfortunately not. I've run across this problem with Maven projects: you have on source folder for your main Java code and one for your test Java code. The test Java code should be able to access the main Java code, but the other direction should not be possible (and that's enforced during the normal Maven build). But in Eclipse each class can see and access each other, so you get situations where the problem (of a main class accessing a test class) only becomes visible on a manual Maven build (or during the CI cycle). Commented Mar 1, 2011 at 9:20

1 Answer 1

3

Create two separate projects is the obvious answer...

you can always have each folder build to a different folder but... classpath is defined per projects so you still end up with them in the same classpath and thus available to each-other...

really here there is no issues... separate projects will effectively create the effect that you want.

Out of curiosity here, why the requirement to be in the same project ? It just sounds needlessly complicated. Don't try to go against the tools you are using, as much as they can be a blessing when use right if you bend them in unwieldy ways they will make you suffer immeasurable pains.

---- Edit ----

If I understand correctly you want the convenience of having a single item in the repository to contain both the problem and the solution but want them as separate entities. You could acheive this by having two distinct project as sub-folder of a single root. Enter the root in your archive. Then to get the projects you have two possible options

  1. Get them to get the projects separately by first browsing to the proper sub-folder and import from there

or

  1. Get them to get the root and import it all, then get them to import projects and point the import to the root folder. Normally Eclipse will detect the projects and allow you to import them form there. This will then create two projects in the workspace as though you created them there directly but will reside as sub-folders of the root item. This is how Maven deals with modules in it`s default configuration.

Not perfect but it could do the trick.

Sign up to request clarification or add additional context in comments.

2 Comments

It's not a real work project - it's an exercise, and i've wanted to separate the exercises from the solutions. The reason I want it to be in the same project is that it is easier for student to check it out from the repository. I thought there isn't an easy solution for that, so probably I'll go with the 2 projects solution...
So basically you want this out of convenience for the repository you have for your projects. One way you can do it is to create the projects in a single root folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.