Link to home
Start Free TrialLog in
Avatar of ScottyMac
ScottyMac

asked on

Importing my own package

I created my own HTMLObject package where HTMLObject.class is the root of the package.  I created a folder called "mypackages" and then a sub-dir called "html".  The classpath was set to the c:\mypackages; dir.  All the .java files were located in the "html" folder, and the first line in all of them is "package html".  All of the files are compiled and now all the .class files are in the "html" folder.

How do I import this package "html" into a servlet of my choice?  I tried
import html.*;  but I received a lot of errors:

File .\HTMLDocument.java does not contain type HTMLDocument as expected.  Please adjest the class path so that the file does not appear in the unnamed package.

Class HTMLDocument not found.

-----------------------
HTMLDocument is one of the class files that was in the "html" folder.

Any suggestions?


scottymac

Avatar of sankars98
sankars98


 try to compile your HTMLDocument.java like this

 c:\mypackages\html\> javac -d c:\mypackages HTMLDocument.java

Sankar S.

 Before that , delete the existing *.class files under html
 directory and check where you are getting the
 class files.
Avatar of ScottyMac

ASKER

This way places the class files into the dir "html" because I called the package "html" on the top line of the .java file.  If the "html" dir was not created previously and the .java files were in the main dir "mypackages", it creates the dir, "html".

But, I'm still having problems, I have my classpath set to c:\mypackage;c:\mypackage\html;.  and I'm still getting errors when I try to compile my servlet.

Error:
File .\HTMLDocument.class does not contain type HTMLDocument as expected, but type html.HTMLDocument.  Please remove the file, or make sure it appears in the correct sub-dir of the class path.

Class HTMLDocument not found.

-----------------------------
So, I can now create the package, but I am unable to import it from a servlet.




 In your classpath , remove
 c:\mypackage\html; and try.
 I am not sure. It might be a problem.  
ASKER CERTIFIED SOLUTION
Avatar of Ravindra76
Ravindra76

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial