Results 1 to 2 of 2
  1. #1
    java_on_fire is offline Member
    Join Date
    Mar 2010
    Posts
    19
    Rep Power
    0

    Default launching application with java command line

    Hi all,

    I have been stuck doing this for few hours, i appreciate if someone can help me out!

    I have two classes;

    Java Code:
        package test;  
          
        public class TestingClient {  
          
            /** 
             * @param args 
             */  
            public static void main(String[] args) {  
                // TODO Auto-generated method stub  
                System.out.println(new Client().getCounter());  
            }  
          
        }
    and

    Java Code:
        package test;  
          
        class Client {  
            private int counter;  
              
            Client(){  
                counter = 10;  
            }  
              
            public int getCounter() {  
                return counter;  
            }  
        }
    I'm running ubuntu 11.10 and i have tested java and javac and they work.

    The following is my directory structure:
    Java Code:
    home/workspace/Testing/src/test/TestingClient.java  
    home/workspace/Testing/src/test/Client.java
    the current directory is src

    I used:

    Java Code:
    javac TestingClient.java
    and it created the class file TestingClient.class inside src/test

    Java Code:
     javac -d ../classes Client.java
    and it created the class file Client.class inside Testing/classes

    now when i use:

    Java Code:
     java -cp ../classes test.TestingClient
    i get this error message:
    Error: Could not find or load main class test.TestingClient

    what i'm doing wrong?

    PS: later on, i put both classes inside the bin folder inside the project folder and java command line worked! could it be the -cp?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: launching application with java command line

    The TestingClient class is in the test package. The java program will look in a test folder for the TestingClient.class file.
    You say that the TestingClient.class file is in the classes folder, not a test folder.

    The classpath for the java command should point to the folder containing the test folder. The test folder should contain the TestingClient.class file.

Similar Threads

  1. Replies: 16
    Last Post: 09-17-2011, 03:41 AM
  2. How do you use the Mac command line for Java?
    By java beginner in forum New To Java
    Replies: 16
    Last Post: 05-07-2011, 05:34 AM
  3. tracing java application line by line using netbeans
    By chandrasekhar123 in forum NetBeans
    Replies: 1
    Last Post: 08-03-2010, 03:46 PM
  4. Replies: 2
    Last Post: 07-02-2010, 03:20 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:23 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
  •