Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default package and classpath

 
vikas jain
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a directory structure like this.

c:\Nikhil\SCJP
c:\Nikhil\SCJP\com

Now I have two java files.

test1.java is in c:\Nikhil\SCJP directory.



I compile it using the following command.


C:\Nikhil\SCJP>javac -classpath "" test1.java

Second file test2.java is in c:\Nikhil\SCJP\com directory.



I am trying to compile it using the following command.

C:\Nikhil\SCJP>javac -d . -classpath "." .\com\test2.java

And it is not working. I don't know why but I am not able to catch the issue.

The compiler thinks that test1 is in com package ( as i have not used any import statement..so the compiler will assume that the file is in the current package)

How can I make it work.
[ April 26, 2006: Message edited by: Nikhil Agrawal ]
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are under windows, separate items in the class path with semicolon.

>javac -classpath .;c:\myPath\xyz.jar;c:\anotherPath\abc.jar MyClass.java

If you are under Linux, with colon

>javac -classpath .:/myPath/xyz.jar:/anotherPath/abc.jar MyClass.java
 
vikas jain
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..but that doesn't solve the issue that I am having or does it?
 
vikas jain
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like it is the rule..

You can't use classes in the default package from a named package.
 
Changchun Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a class which having package declaration can not import default package's class or static members
hence you can not do that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic