Results 1 to 7 of 7
  1. #1
    Skiller is offline Member
    Join Date
    Jan 2011
    Posts
    67
    Rep Power
    0

    Default Folders to group source files

    I'm starting to have more source files than is easily managed and was wondering if it's possible to put the .java files into sub-folders of the package folder they are already in?

    I'm using eclipse if that makes a difference.
    Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You would have to change how you package them.

    For example

    Java Code:
    import java.awt.*;
    imports the source files in the java/awt folder, but none of the subdirectories in there.

    Java Code:
    import java.awt.event.*;
    Imports the source files in java/awt/event folder.

  3. #3
    Skiller is offline Member
    Join Date
    Jan 2011
    Posts
    67
    Rep Power
    0

    Default

    Thought that might be the case :(. Will that mean that they wont be displayed as a tree/hierarchy in the "Package Explorer" of eclipse? The current packages I have don't seem to display that way and it would make things a little less readable if I can't see the hierarchy at a glance :(.

    C++ spoiled me rotten with all it's niceties so I get a little disappointed when Java lacks the same features. Oh well, at least it'll be better than it currently is, thanks for the quick reply :)
    Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by Skiller View Post
    I'm starting to have more source files than is easily managed and was wondering if it's possible to put the .java files into sub-folders of the package folder they are already in?
    You should really have been using packages from the first class that you wrote. They explain how to use them here: Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages)

    Quote Originally Posted by Skiller View Post
    Thought that might be the case :(. Will that mean that they wont be displayed as a tree/hierarchy in the "Package Explorer" of eclipse? The current packages I have don't seem to display that way and it would make things a little less readable if I can't see the hierarchy at a glance :(.
    You've probably not defined your folders as source folders for your project in Eclipse. This has less to do with Java but more with your ability to use eclipse. Eclipse also has different types of viewing your projects according to your preference.


    Quote Originally Posted by Skiller View Post
    ..
    C++ spoiled me rotten with all it's niceties so I get a little disappointed when Java lacks the same features. Oh well, at least it'll be better than it currently is, thanks for the quick reply :)
    Nah, this doesn't really have anything to do with Java lacking features. There is nothing to suggest that source code organization is better in C++ than in Java.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

  6. #6
    Skiller is offline Member
    Join Date
    Jan 2011
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    You should really have been using packages from the first class that you wrote. They explain how to use them here: Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages)
    I'm using a few packages already but they are just the ones that were created automatically when I created the project. The project started off as just a test to see that my idea was actually viable on the Android platform and as each part proved viable I just kept coding more parts so I wasn't really expecting to get this far when I started and as a result I didn't expect to run into this problem. Normally I would have used some sort of namespacing before I got to this point but I didn't think it was going to be necessary. I'll probably start up a new project for this soon and sort out the packages when copying the code across to it, along with any other refactoring that might be beneficial.

    Anyway thanks for the link, saves me having to look it up :D


    Awesome, that's going to neaten things up heaps, thanks :D.
    Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Awesome, that's going to neaten things up heaps, thanks

    You're welcome.

Similar Threads

  1. Searching directories for folders and .txt files
    By XDrew574X in forum New To Java
    Replies: 1
    Last Post: 03-29-2011, 09:41 PM
  2. Configuring Java source folders for eclipse
    By kfir.wolfson@gmail.com in forum Eclipse
    Replies: 8
    Last Post: 10-01-2010, 12:11 PM
  3. Replies: 4
    Last Post: 10-10-2009, 12:26 AM
  4. Replies: 0
    Last Post: 01-29-2009, 10:43 AM
  5. Replies: 20
    Last Post: 12-17-2007, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •