Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Creating source folder programmatically
Creating source folder programmatically [message #316726] Fri, 15 June 2007 17:41 Go to next message
Eclipse UserFriend
Originally posted by: neelesh.thakur.yahoo.com

Hi

Can any one tell me how can I create source folder programmatically. I
want to create source folder in my plugin.

I have tried but it is giving Java Model Exception.. here is my code..

IProject iProject = iJavaProject.getProject();
IFolder iFolder = iProject.getFolder("src-JUnit");
IPath sourceFolderPath = iFolder.getFullPath();
IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath);
IClasspathEntry[] entries = iJavaProject.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[newEntries.length - 1] = entry;
iJavaProject.setRawClasspath(newEntries, new NullProgressMonitor());

and here is the exception trail..

Java Model Exception: Java Model Status [Cannot nest 'exp/src-JUnit'
inside 'exp'. To enable the nesting exclude 'src-JUnit/' from 'exp']
at
org.eclipse.jdt.internal.core.JavaModelOperation.runOperatio n(JavaModelOperation.java:775)
at
org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(Ja vaProject.java:3016)
at
org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(Ja vaProject.java:3032)
at
treeviewmultpage.views.SampleView.createJunitSRCFolder(Sampl eView.java:275)

Any help will be appreciated.

Thanks
Neelesh
Re: Creating source folder programmatically [message #316737 is a reply to message #316726] Sun, 17 June 2007 09:07 Go to previous messageGo to next message
Eclipse UserFriend
What is exp? Is that your project's name? Is the root project itself a
source folder? The error sounds like exp is a source folder and you're
also trying to make exp/src-JUnit a source folder.

Regards,
Rem
Re: Creating source folder programmatically [message #316742 is a reply to message #316737] Sun, 17 June 2007 12:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: neelesh.thakur.yahoo.com

yes exp is project...
Re: Creating source folder programmatically [message #316743 is a reply to message #316742] Sun, 17 June 2007 12:22 Go to previous messageGo to next message
Eclipse UserFriend
Neelesh Thakur wrote:
> yes exp is project...

So...is the root project a source folder itself? I noticed you're
getting the project's classpath and then appending to it. Check the
project's classpath and see what's there first.
Re: Creating source folder programmatically [message #316746 is a reply to message #316743] Sun, 17 June 2007 17:27 Go to previous message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

If you have a folder A and a folder A/B, then you need to update the parent folder (A) to exclude any of B's content (so that A doesn't compile all of B's stuff).

This happens automatically when you do it in the menus (something like 'update exclusion lists automatically) but I suspect you have to do it on your own if you want to do it programmatically.

You could try having different folders, e.g. A and B, which wouldn't need that workaround.

If your main location is the project root itself, then you could try removing that. It probably involves trying to get the parent folder (e.g. A above, or the project root) and then setting exclusion filters on the IClassPathEntry

http://help.eclipse.org/help32/topic/org.eclipse.jdt.doc.isv /reference/api/org/eclipse/jdt/core/IClasspathEntry.html

However, I don't know how you'd go about changing them, or even if this is the right approach. Have a look and see how it's done when a new source folder wizard is running.

Alex.
Previous Topic:Eclipse 3.2.1 does not open
Next Topic:Problem with java application
Goto Forum:
  


Current Time: Tue May 13 17:53:01 EDT 2025

Powered by FUDForum. Page generated in 0.03329 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top