Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » changing an ordinary folder to a source folder in a project
changing an ordinary folder to a source folder in a project [message #181774] Mon, 27 November 2006 08:37 Go to next message
Eclipse UserFriend
Originally posted by: sri1025.gmail.com

I have a folder in my project and I want to change it into a source
folder. And the project is a Java Project. How should I do this?

Thank you,
Srikanth
Re: changing an ordinary folder to a source folder in a project [message #181777 is a reply to message #181774] Mon, 27 November 2006 09:00 Go to previous messageGo to next message
Remy Suen is currently offline Remy SuenFriend
Messages: 462
Registered: July 2009
Senior Member
Srikanth wrote:
> I have a folder in my project and I want to change it into a source
> folder. And the project is a Java Project. How should I do this?

If you mean for coding, just right-click on the folder in the Package
Explorer View, then Build Path -> Use as Source Folder.

If you mean how to do it using the JDT APIs, then you need to update
your IJavaProject's raw classpath.

// get your IProject
IProject project = getProject();
// create the corresponding IJavaProject
IJavaProject ijp = JavaCore.create(project);
// get the folder
IFolder folder = project.getFolder("nameOfNewSrcFolder");
// create a new source entry for it
IClasspathEntry entry = JavaCore.newSourceEntry(folder.getFullPath());
// retrieve the project's current classpath
IClasspathEntry[] entries = ijp.getRawClasspath();
// create a new array with the original entries and the new source entry
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[newEntries.length - 1] = entry;
ijp.setRawClasspath(newEntries, new NullProgressMonitor());

That should be the general gist of it.

Regards,
Rem
Re: changing an ordinary folder to a source folder in a project [message #181782 is a reply to message #181777] Mon, 27 November 2006 09:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sri1025.gmail.com

> If you mean for coding, just right-click on the folder in the Package
> Explorer View, then Build Path -> Use as Source Folder.

Thanks Rem!

I meant for coding and sorry for not specifying that in the first post. I
use Java Browsing perspective for coding and Resource perspective for
dealing with the other folders so didn't find any options when I right
clicked on the folder which I wanted to change to a source folder.

Just got addicted to Java Browsing perspective and unable to come out of
it :D

Thank you very much,
Srikanth
Re: changing an ordinary folder to a source folder in a project [message #181834 is a reply to message #181782] Mon, 27 November 2006 18:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse4.rizzoweb.com

Srikanth wrote:
>> If you mean for coding, just right-click on the folder in the Package
>> Explorer View, then Build Path -> Use as Source Folder.
>
> Thanks Rem!
>
> I meant for coding and sorry for not specifying that in the first post.
> I use Java Browsing perspective for coding and Resource perspective for
> dealing with the other folders so didn't find any options when I right
> clicked on the folder which I wanted to change to a source folder.
>
> Just got addicted to Java Browsing perspective and unable to come out of
> it :D

I, too, prefer Java Browsing perspective. However, there are several
ways you can accomplish this from that perspective:
a) you can use Window > Show View... to open the Package Explorer and
make it a Fast View that is minimized when not in use.
b) You can right-click the project name and choose Properties. On the
Build Path section of the Properties you can select additional source
directories.

Hope this helps,
Eric
Re: changing an ordinary folder to a source folder in a project [message #181933 is a reply to message #181834] Tue, 28 November 2006 08:25 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Eric Rizzo wrote:

> Srikanth wrote:
>
>>> If you mean for coding, just right-click on the folder in the
>>> Package Explorer View, then Build Path -> Use as Source Folder.
>>
>>
>> Thanks Rem!
>>
>> I meant for coding and sorry for not specifying that in the first
>> post. I use Java Browsing perspective for coding and Resource
>> perspective for dealing with the other folders so didn't find any
>> options when I right clicked on the folder which I wanted to change
>> to a source folder.
>>
>> Just got addicted to Java Browsing perspective and unable to come out
>> of it :D
>
>
> I, too, prefer Java Browsing perspective. However, there are several
> ways you can accomplish this from that perspective:

Me too ;-)
What I recommend is to replace the Projects view with the Package
Explorer and save the perspective again. There's a filter in the Package
Explorer that allows you to filter the Java files (if you don't want to
see them).

HTH
Dani

> a) you can use Window > Show View... to open the Package Explorer and
> make it a Fast View that is minimized when not in use.
> b) You can right-click the project name and choose Properties. On the
> Build Path section of the Properties you can select additional source
> directories.
>
> Hope this helps,
> Eric
Previous Topic:org.eclipse.core.runtime.CoreException
Next Topic:Internal error on JDT
Goto Forum:
  


Current Time: Fri Apr 26 12:29:27 GMT 2024

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

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

Back to the top