Meaningless Drivel is fun!*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse - add a new folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse - add a new folder" Watch "Eclipse - add a new folder" New topic
Author

Eclipse - add a new folder

bob reilly
Ranch Hand

Joined: Jan 22, 2007
Posts: 44
I have a Java application requiring modification. Viewing through Eclipse's Package Explorer, you can see the directory tree. I need to place a new folder in the middle of this directory tree. If you have folders "aaa.bbb.ccc" and "aaa.bbb.eee" but want to place another folder between them (ie. aaa.bbb.ddd) - is right clicking "aaa.bbb.ccc" to "New" ==> "Folder" and enterering the name going to do it (don't think this is it)? Or create a new folder on the source directory (that resides below the Project)? Are there other concerns?

By the way - as an alternative to using Eclipse - in a windows workstation envrionment - could simply enter a new folder name in the directory and after doing that, refresh in Eclipse?

Any comments / URLs would be appreciated. Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18716
    
    8

"Between" is a red herring because Eclipse will automatically arrange the folders in order for you.

And you don't want to create a new source folder, you want to create a new package in an existing source folder, right?

So my guess would be to right-click on the parent of the existing packages and select "New, Package".
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

Yes, you can create a folder using OS services (GUI or command line) and refresh an Eclipse project and it will show up, but it's easier to simply use the Navigator in Eclipse and skip the refresh.

As for "how to...?" why not try it and see? If you create a folder (or package level) in the wrong place, right-click on it, select Refactor/Move and move it to where you want it.


Customer surveys are for companies who didn't pay proper attention to begin with.
bob reilly
Ranch Hand

Joined: Jan 22, 2007
Posts: 44
Thank you for the information. As far as trying things in Eclipse - you're right - but first I want my workstation backed up in the event I run into issues that I want to recover from.

One last question - after I create a new package in a src folder - and now want to create a new java source file to it. That's File >> New >> Class? After concerns here? Please bear with my newbie questions. Any URLs would be appreciated.

Thank you both for responding...
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

Better yet, within the Package Explorer right-click the package you want to create the source file in and select New | Class. Then the New class dialog will be prefilled with the package name. Of course, you can always change the package name if you like.

Also, no need to backup the entire workstation - just zip up your project's directory (or make a copy of the directory). You can restore the project from that if things go horribly wrong.


JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

Peter Johnson wrote:Better yet, within the Package Explorer right-click the package you want to create the source file in and select New | Class. Then the New class dialog will be prefilled with the package name. Of course, you can always change the package name if you like.


Helpful hint #1: Eclipse will often create multiple folder/package levels for you automatically. I always try that first just in case what I'm doing supports taking the easy way out.

Peter Johnson wrote:
Also, no need to backup the entire workstation - just zip up your project's directory (or make a copy of the directory). You can restore the project from that if things go horribly wrong.


Helpful hint #2: You can zip up (backup) a project by using the Eclipse export feature. For that matter, you can even make an unzipped backup using Export.

However, Undo/Redo are often available as well.

Eclipse really isn't all that fragile when it comes to stuff like this, so just play around with it until you feel confident that you know what it's doing.
bob reilly
Ranch Hand

Joined: Jan 22, 2007
Posts: 44
Good informatin here - thank you.

One last question and I'm done. With the New Java Class - there's a section "Which method stubs would you like to create". There are 3 checkboxes. I can safely elminate the first - "public static void main(String[] args)". The second "Constructors from superclass" and third "Inherited abstract methods" - I doubt either are going to take place - however I'm looking to extend an existing package. What's the impact in checking or not checking? Can you revisit later and update this attribute option? That's it.

Thanks again for your responses.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

What's the impact in checking or not checking?

If you check them, you get the indicated methods automatically when the class file is created. If you don't check them, you can always add them later - right-click within the source file editor window and select Source. Those two options, and many more, will show up in the submenu. If you do check them and decide you don't want the generated methods, you can easily delete them within the source file editor window.

I usually don't select the constructor option preferring to do that from the Source menu later. If I know that I am extending an abstract class or implementing an interface, I usually select the inherit abstract methods checkbox.

But try it both ways and see which one works the best for you. One of the nice things about the multitude of options that Eclipse provides is that you can adapt Eclipse to your way of working.
 
 
subject: Eclipse - add a new folder