Results 1 to 5 of 5
  1. #1
    Vardiane is offline Member
    Join Date
    Apr 2011
    Location
    Krakow, Poland
    Posts
    2
    Rep Power
    0

    Question How to use my own packages?

    How can I import my own packages into .java files from different packages without setting the CLASSPATH variable and only specifying javac -claspath <path>?
    i.e. I have a folder Program and in this folder I have bin and src folders. Where should I put my package files? I tried and put them into src/com/mydomainname/mypackage and then I created another file, in the /src directory, Main.java in which I added statement "import com.mydomainname.mypackage.*;"
    Then, when compiling from my Program directory, I used "javac Main.java -classpath /src" and it didn't work.
    How can I make this work? What's the usual place to put your own packages in?

  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

    What do you mean "it didn't work" ? Did you get any errors? If so what were they? Make sure the folders and package and import match the case of the folder names.

    You may have to expand the -cp with something like
    Java Code:
    javac -cp .;source folder file.java

  3. #3
    Vardiane is offline Member
    Join Date
    Apr 2011
    Location
    Krakow, Poland
    Posts
    2
    Rep Power
    0

    Default

    The error I get is "package com.mydomainname does not exist".
    It still doesn't work when I use "javac -cp ./src Main.java" .

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

    Default

    Did you separate the two with a semi colon? What is the package statement in the packaged code? Did you compile the package code? I am not great with packaes either but I am giving you some ideas to try until someone with more experience comes along.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,256
    Rep Power
    19

    Default

    Did you separate the two with a semi colon?
    ... for Windows. On a Linux box you'd use a colon instead.

    db

Similar Threads

  1. Packages
    By urbim in forum Eclipse
    Replies: 2
    Last Post: 07-02-2009, 02:01 PM
  2. packages
    By fogus in forum New To Java
    Replies: 1
    Last Post: 03-24-2009, 06:14 AM
  3. Replies: 3
    Last Post: 02-12-2008, 11:03 AM
  4. packages
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 12:10 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
  •