Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compiling java package class referring a default package class.  RSS feed

 
sandip singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I am trying to compile a java class having a package defination referring a java class with a default package.

The code for the default package class is .

public class Test{.


public static void main(String[] args){
System.out.println("Hello World!");

}
}

This class compiles fine.

I have another class called PackJava, whose code is :

package test;
import Test;
public class PackJava{
public static void main(String[] args){
Test test = new Test();
System.out.println("Hello World!");
}
}


I have Test file in the windows path
D:\development\packagetest\example
and the PackJava java file in the path
D:\development\packagetest\example\test
I have set the CLASSPATH environment varibale as
D:\development\packagetest\example;.


When I try to compile the PackJava from the
D:\development\packagetest\example path giving the command as
javac -classpath . test\PackJava.java
or
javac -classpath %CLASSPATH% test\PackJava.java
it gives me error,
Do any of you have an idea of the parameter i should pass
to the -classpath option
Thanks
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no reason to import things from the deault package. In fact, the java compiler won't let you (you will receive an "expected ." error). Remove the line "import Test; " and try compiling again.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!