java compile, directory confusion
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: java compile, directory confusion

Threaded View

  1. #1
    Join Date
    May 2002
    Location
    Germany
    Posts
    442

    java compile, directory confusion

    I think the answer to my question must be an obvious one and shorter than even the question I am a C++ programmer struggling with the first java program for a day or so. There is some code I have to port to java (not long, only a few classes but I have to keep the structure as must as possible). First I try to have two files compiled and running but could not achieve that for a day.

    My current directory structure is like:
    c:\MyProject\proj1.java\Api\_classes
    c:\MyProject\proj1.java\Api\Api.java
    c:\MyProject\proj1.java\Api\Test\Test.java

    The files are like:
    Api.java:
    Code:
    package Api;
    
    public class Api {
    }
    Test.java:
    Code:
    package Api.Test;
    
    import Api.*;
    
    public class Test {
        public static void main(String[] args) {
            Api a = new Api();
            System.out.println("Hello, world");
        }
    }
    I actually created those with NetBeans and can compile/run. It needs to be integrated to the usual make process (now on Windows, later on linux). That should be no problem given that compilation of those will be successful (maybe .jar later, not that far yet).

    So, how far I got:
    Code:
    C:\MyProject\proj1.java>javac -d C:\MyProject\proj1.java\_classes C:\MyProject\p
    roj1.java\Api\Api.java
    OK...

    Code:
    C:\MyProject\proj1.java>javac -d C:\MyProject\proj1.java\_classes C:\MyProject\p
    roj1.java\Api\Test\Test.java
    OK...

    Code:
    C:\MyProject\proj1.java>java -cp C:\MyProject\proj1.java\_classes C:\MyProject\p
    roj1.java\_classes\Api\Test\Test
    Caused by: java.lang.ClassNotFoundException: C:\MyProject\proj1.java\_classes\Ap
    i\Test\Test
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    Could not find the main class: C:\MyProject\proj1.java\_classes\Api\Test\Test.
    Program will exit.
    FAIL...

    Why?
    Last edited by luftwaffe; September 20th, 2012 at 12:04 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center