Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Red face learning packages

    hello I am not able to compile this package structure pleas help.
    Dir structure
    c:\jpro\p\testclass1.java
    c:\jpro\p\testclass2.java

    both the class are created in plackage p in directory c:\jpro
    testclass1
    <code>
    package p;

    class testclass1
    {
    public static void main(String[] args)
    {
    System.out.println("Hello World!");
    }
    }
    </code>
    testclass2
    <code>
    package p;
    class testclass2
    {
    public static void main(String[] args)
    {
    System.out.println("testclass2!");
    }
    }
    </code>

    I am compiling
    C:\jpro>javac p.testclass2.java
    javac: file not found: p.testclass2.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    but if i compile from inside the package it compiles fine but do not run.I dont know missing some thing really silly in here please help

    C:\jpro\p>java testclass1
    Exception in thread "main" java.lang.NoClassDefFoundError: testclass1 (wrong name: p/testclass1)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Last edited by shashanksworld; 03-25-2010 at 01:33 PM.

  2. #2
    fceruti is offline Member
    Join Date
    Mar 2010
    Posts
    20
    Rep Power
    0

    Default

    go to the directory where the testClass1 and 2 files are and type:

    javac testClass1.java
    javac testClass2.java

    Theres no such thing as "compiling a package"

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    javac p/testclass2.java

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    As i pointed out, they're not using javac correctly.

    "p.testclass2.java" is not the correct filename, which is why it's complaining.

    It's a path, not a package...so "p\testclass2.java".

    But, as you say, they don't appear to be runnin gthe same file that they're compiling.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Simply he compiles a one and try to run another in a different folder path, in wrong way. Don't know that OP got it clearly and tried it out.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    Hard to tell since they haven't come back...and it's just us two chattering away.
    :)

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    Hard to tell since they haven't come back...and it's just us two chattering away.
    :)
    Yeah, that's true. Have to wait for our OP.

Similar Threads

  1. Pre-requisites for learning JSP
    By xtiano77 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-23-2010, 06:03 PM
  2. e-learning
    By Vipan Konnect in forum Advanced Java
    Replies: 3
    Last Post: 11-21-2009, 04:29 PM
  3. Self-directed learning
    By Mr.Beans in forum Forum Lobby
    Replies: 3
    Last Post: 05-05-2009, 10:40 PM
  4. Learning Java
    By jjoshua2 in forum New To Java
    Replies: 2
    Last Post: 12-20-2008, 02:46 AM
  5. Replies: 3
    Last Post: 02-12-2008, 11:03 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
  •