aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes default package and classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "default package and classpath" Watch "default package and classpath" New topic
Author

default package and classpath

vikas jain
Ranch Hand

Joined: Apr 21, 2006
Posts: 37
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

Joined: Dec 31, 2004
Posts: 961
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

Joined: Apr 21, 2006
Posts: 37
Thanks..but that doesn't solve the issue that I am having or does it?
vikas jain
Ranch Hand

Joined: Apr 21, 2006
Posts: 37
It looks like it is the rule..

You can't use classes in the default package from a named package.
Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
if a class which having package declaration can not import default package's class or static members
hence you can not do that
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default package and classpath