• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

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?


  • 3
1 Solution

 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.
ScottyMacAuthor Commented:
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.

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.  

Hi ScottMac,If you follow some steps, you will get succeeded.

This question comes second time in two days.

If you want solution means visit this question in EE which is answered by me.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10226482 .

with title Packages and Packages.

If you wish don't to loose your points and still get solution means follow the steps.

      1.  go to c:\ mypackages

      2. Save HTMLDocument.java here. First line should be            package html;. Don't write file in html directory

      3. use
                javac -d . HTMLDocument.java

                It will crate html  package.
                HTNLDocument.class will reside in this directory

       4. Remove the HTMLDoucment.java from c:\mypackages
           i.e Copy it any where. But you must hide.

       5. Write another file which user this file in any directory

           import html.*;

         Now it won't give any problems.

       Beaware that the HTMLDocument class is public and the methods you are calling from this class are public.

Best of luck.



Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now