0

I want to create more than one source folder in a java project programmatically.Now I am able to create one source folder with the java project .But if I give more than one like /src/main/java & /src/test/java . enter image description here

It is creating like above picture. I am using below code for creating source folders in java project.

 for (String srcPath : projectSrcPath.split("\\s+")) {
final IClasspathEntry[] buildPath = { JavaCore.newSourceEntry(project.getFullPath().append(srcPath)),
                        JavaRuntime.getDefaultJREContainerEntry() };

javaProject.setRawClasspath(buildPath, project.getFullPath().append("bin"), null);
createFolder(project.getFullPath().append(srcPath));
}

Can anyone please tell me what is wrong I am doing here?

1 Answer 1

2

You need to add all source folders to buildPath. Simply create more entries with JavaCore.newSourceEntry() plus the correct path.

Don't forget to create all the folders!

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

2 Comments

Thank you @Aaron Digulla.I'll try with adding all source folders to buil path.Can u please some example of 2nd option?
@Anu Just look at the last line of the code sample you posted in your question!?

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.