File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package Compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package Compilation" Watch "Package Compilation" New topic
Author

Package Compilation

Srinivas Ivaturi
Ranch Hand

Joined: Jan 28, 2003
Posts: 50
I have two classes on under package one outside pacakge.

package com.xyz.abc;

class Test1
{
Test1()
{
System.out.println(" Test 1 ");
}
}

I could able compile this javac -d . Test1.java

Package structure is created and class file is placed.

I have another class which tries to use this class but that class has no package structure and trying to import the Test class


import com.xyz.abc.*;
class Test
{
Test()
{
System.out.println("Testing ");
}

public void add(Test1 aTest)
{
System.out.println("a Testing ");
}
}

I am getting

D:\Testing>javac -classpath D:\Testing\com\xyz\abc Test.java
Test.java:1: package com.xyz.abc does not exist
import com.xyz.abc.*;
^
Test.java:9: cannot access Test1
bad class file: D:\Testing\com\xyz\abc\Test1.class
class file contains wrong class: com.xyz.abc.Test1
Please remove or make sure it appears in the correct subdirectory of the classpath.
public void add(Test1 aTest)
^
2 errors


May I know Why this is giving error.

Thanks
Srinivas Ivaturi
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Try this:
javac -classpath D:\Testing Test.java

You're supposed to point javac to the top of your directory structure. javac will see the "import com.xyz.abc.*;" statement and find D:\Testing\com\xyz\abc\Test1.class
[ November 19, 2004: Message edited by: Mike Gershman ]

Mike Gershman
SCJP 1.4, SCWCD in process
Srinivas Ivaturi
Ranch Hand

Joined: Jan 28, 2003
Posts: 50
I tried as you said even that is giving same problem for me.

Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Please display the full directory paths of Test1.class and Test.java and post them here.

Also, please post the exact javac command you used on Test.java.
 
 
subject: Package Compilation