Results 1 to 6 of 6
  1. #1
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Question package statement in java files won't run outside of eclipse

    I am learning eclipse and java concurrently.

    Eclipse puts a package statement at the head of a class file. The class will compile and run inside of eclipse, but I can not run it from the command line (java myclass), although it compiles. I've found that removing the package statement allows the program to compile and run from the command line.

    Can make the adjustment, but what is under the hood?

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    thats because you don't have your CLASSPATH setup correctly. please post your classpath here. type echo %classpath% in cmd to find it.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Read the sun tutorial on how to compile and run your program and on use of package statement. This will answer all of your questions.

  4. #4
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default Found answer, still doesn't work

    So, where in the sun tutorial do I find this information? Lots of material there, if I only knew where to look. I did go back to the the beginning and found some relevant information, even looked under common problems. Don't mind doing the leg work, but I am asking because I don't know where to look or what I missed the first go around. Finally found the answer in a dated version of "Core Java - Vol. 1" has a fairly comprehensive treatment of packages in chapter 4.

    What I finally found out is that CLASSPATH + PACKAGE + somefile.class should evaluate to the location of "somefile.class". If there is a value in CLASSPATH, the current directory -> . <- is needed.

    .;g:\workspace\LockObjects\src; is my class path. rdt_LockObj is my package.

    Of course, now that I know all the answers, it still doesn't work.

    What am I missing?

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    did you put file.class file in folder:
    g:\workspace\LockObjects\src\rdt_LockObj\file.clas s ?

    also try running w/:
    java rdt_LockObj.file
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    I was running java.exe from the same file.

    java rdt_LockObj.myfile worked
    Thanks rdt

Similar Threads

  1. Importing a zipped package to Eclipse
    By Abder-Rahman in forum Eclipse
    Replies: 10
    Last Post: 02-24-2010, 05:26 PM
  2. importing .java files into eclipse
    By nickl2002 in forum Eclipse
    Replies: 1
    Last Post: 01-18-2009, 11:06 PM
  3. Multiple Eclipse package installation
    By Robert Waltz in forum Advanced Java
    Replies: 1
    Last Post: 11-23-2008, 12:24 AM
  4. org.eclipse.core package
    By Eranga in forum Advanced Java
    Replies: 2
    Last Post: 07-07-2008, 05:26 AM
  5. How to import a package in Eclipse?
    By naipulb in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 11:04 AM

Posting Permissions

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