• Post Reply Bookmark Topic Watch Topic
  • New Topic

Package Compilation

 
Srinivas Ivaturi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Srinivas Ivaturi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried as you said even that is giving same problem for me.

 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!