5
package com.test01;

public class test01 {
    public static void main(String[] args)
    {
        System.out.println("hi");
    }
}

I think the java application launcher is very stupid. I have point out the test01.class position:
java -cp . test01(.class)
but this doesn't works. It's very hard to use.

1
  • 1
    the -cp have to point out the dir which contain 'com'..... so, this works: java -cp ./bin/(contain com) com.test01.test01 Commented Jun 11, 2011 at 7:29

2 Answers 2

20

You would run

java com.test01.test01

but having a class with the same name as a package is a really bad idea (as well as not following the Java naming conventions).

You'd need to run it with the relevant class on the classpath. For example, you could just compile it like this (from the "root" of your source tree):

javac -d . [path to source file]
java com.test01.test01

or if you've got your source organized appropriately already:

javac com\test01\test01.java
java com.test01.test01
Sign up to request clarification or add additional context in comments.

3 Comments

OK, now that you have included the compiling part, I've deleted my answer for redundancy.
What if I have a lib folder and out folders?
@Kieveli: It's not clear what you mean. I suggest you ask a new, detailed question.
3

You should be changing over to the base directory from where the classes start

java -cp $CLASSPATH:.: com.test01.test01

But naming a class "test01" is not a good naming convention.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.