#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    82
    Rep Power
    11

    Eclipse: start a new Java project with an existing package??


    I have Java classes in (1) my choice of directory and (2) my choice of package.

    How do I create a NEW Eclipse project that uses my exising Java classes with their packages?

    (The Eclipse issue I'm facing: It keeps trying to move my files into a new nested directory named after my package... and I don't want anything to move. Or it wants to delete the package statement in my source code. Nope, I don't want that, either.)

    Here are the things I want Eclipse to accept as-is:

    Source directory: C:\jed\prog\utils
    CLASSPATH includes C:\jed (root of the package; good)
    Source file: C:\jed\prog\utils\XYZ.java
    Code:
    package prog.utils;
    class XYZ {}
    (Note that it compiles just fine from a command line. Eclipse is the bugger, not my Java code, not my CLASSPATH outside of Eclipse...)

    So, how do I create a new project (do I start it in C:\jed?) that uses the files in C:\jed\prog\utils and allows the files to keep their "package prog.utils" statements?

    These current definitions do NOT work:
    .classpath:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" path=""/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    	<classpathentry kind="lib" path="C:/jed"/>
    	<classpathentry kind="output" path="bin"/>
    </classpath>
    .project (currently in the "utils" folder):
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <projectDescription>
    	<name>Utils</name>
    	<comment></comment>
    	<projects>
    	</projects>
    	<buildSpec>
    		<buildCommand>
    			<name>org.eclipse.jdt.core.javabuilder</name>
    			<arguments>
    			</arguments>
    		</buildCommand>
    	</buildSpec>
    	<natures>
    		<nature>org.eclipse.jdt.core.javanature</nature>
    	</natures>
    </projectDescription>
    Thanks!
    oak island
    Last edited by oakisland; August 22nd, 2011 at 12:53 PM.
  2. #2
  3. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,186
    Rep Power
    2265
    You should be able to import your existing files by going to:
    File -> New -> Project ... -> Java -> Java Project -> Unclick "Default Location" -> Location: (Browse)
    Select the directory that your classes are located in, and click Next.
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    82
    Rep Power
    11
    Originally Posted by drgroove
    You should be able to import your existing files by...
    Oo, sounds hopeful! Thanks much--will try tonight.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    82
    Rep Power
    11
    (pardon my long time away... I finally tested and have (error) details to report)


    APPROACH #1: set Location to the location of the *.java files (your recommendation)

    Project name: (whatever)
    _ Use default location (unchecked)
    Location: C:\jed\prog\utils

    Bad result: it highlights all my package statements as wrong

    (This suggests to me that I still have to tell it that my CLASSPATH should included C:\jed (since my package is within that) so how do I set that?)



    APPROACH #2: set Location to the path of the package

    Project name: (whatever)
    _ Use default location (unchecked)
    Location: C:\jed (I chose this because the *.java files have package prog.utils; and they are in C:\jed\prog\utils

    Bad result: I clicked Next and it added everything under C:\jed to the new project (I only want C:\jed\prog\utils\*.java in the project)


    Project name: (whatever2)
    _ Use default location (unchecked)
    Location: C:\jed (I chose this because the *.java files have package prog.utils; and they are in C:\jed\prog\utils

    Bad result: I clicked Next and it added everything under C:\jed to the new project (I only want C:\jed\prog\utils\*.java in the project)



    Thanks
    John / oak island
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    82
    Rep Power
    11
    Here's what ultimately worked...

    After using APPROACH #1 above, I kept poking in Configure Build Path in places like Source and Libraries... I have no idea what set this, but this resulting line in .classpath file did the trick:

    <classpathentry kind="lib" path="C:/jed"/>

    The good: I see C:/jed which makes sense, considering my package statements and my awareness that classpath should have C:\jed.

    The bad: Why is it such a pain to set this straightforward fact about CLASSPATH in Eclipse?! Hate it, hate it, hate it...
  10. #6
  11. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,186
    Rep Power
    2265
    Originally Posted by oakisland
    Here's what ultimately worked...

    After using APPROACH #1 above, I kept poking in Configure Build Path in places like Source and Libraries... I have no idea what set this, but this resulting line in .classpath file did the trick:

    <classpathentry kind="lib" path="C:/jed"/>

    The good: I see C:/jed which makes sense, considering my package statements and my awareness that classpath should have C:\jed.

    The bad: Why is it such a pain to set this straightforward fact about CLASSPATH in Eclipse?! Hate it, hate it, hate it...
    More to the point, why should we even have to set a classpath? Why can't the software just parse through the file system and determine where it's necessary files are located?
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    82
    Rep Power
    11
    Meh... I take it back. Those tweaks did not fix things for a similar project. I'm stumped.

IMN logo majestic logo threadwatch logo seochat tools logo