Results 1 to 12 of 12
  1. #1
    rameshiit19 is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Question Accessing Package from a Different Directory

    I have created package in D drive. It exists in D:\ramesh\ directory

    package ramesh;
    public class sourcee
    {
    public void display()
    {
    System.out.println("Source Package");
    }
    }


    I have my another source file in E Drive.It exists in E:\Java


    import ramesh.sourcee; // How to change import statement?
    class deestination
    {
    public static void main(String args[])
    {
    sourcee ss=new sourcee();
    ss.display();
    }
    }



    How do I make import statement to refer to D:\ramesh since my program is in E;\ drive.. ?

    Please help....

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    The import statement is an extension of the classpath. You set the classpath to where the package path starts.

  4. #4
    rameshiit19 is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    @Darryl: I'm new to both the forum . Is both are same? I couldn't get answer for my question yet !

  5. #5
    Ramanjaneyulu is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Default

    Hi Ramesh,

    You need to add the following
    D:\Ramesh
    to already existing classpath variable in Environment Variables.

    for ex:
    C:\program files\java\lib;D:\Ramesh;

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,437
    Rep Power
    18

    Default

    No you don't.
    You add it to the compilation and also the runtime classpath for Java...there is no need to add it to the Environment Variables, indeed that is a common mistake.

    javac -cp <my class paths, including ".">, or java -cp <my class paths>.

    In an IDE there'll be somewhere to add directories.

    However, the thing you point at would normally be the compiled classes, and not the java files...

  7. #7
    rameshiit19 is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    I need to access the package without setting the environment variable .... How can I make it done ?

  8. #8
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    You cannot. Why aren't you allowed to set the environment variable?

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,437
    Rep Power
    18

    Default

    What on earth is wrong with "-cp"?
    Or using a batch file with a local CLASSPATH defined?

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,995
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by Tolls View Post
    What on earth is wrong with "-cp"?
    It looks too tinny; setting an environment variable looks much more woody.

    kind regards,

    Jos ;-)

  11. #11
    rameshiit19 is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    Package works fine after setting environment variable ! Thank you !

  12. #12
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,437
    Rep Power
    18

    Default

    If, by environment variable, you mean setting it in the system, then that is wrong...it may work, but it is very poor practice.

Similar Threads

  1. run package inside anthor package
    By AhmedAdel in forum AWT / Swing
    Replies: 4
    Last Post: 04-20-2010, 11:52 AM
  2. Replies: 7
    Last Post: 11-09-2009, 07:51 AM
  3. : Accessing remote directory???
    By vaskarbasak in forum AWT / Swing
    Replies: 3
    Last Post: 10-15-2009, 08:19 AM
  4. Accessing Active Directory using JNDI
    By Chandran in forum Advanced Java
    Replies: 0
    Last Post: 02-25-2009, 12:04 PM
  5. Accessing Active Directory
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 01-04-2008, 11:25 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
  •