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

ScottyMacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sankars98Commented:

 try to compile your HTMLDocument.java like this

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

Sankar S.
0
sankars98Commented:

 Before that , delete the existing *.class files under html
 directory and check where you are getting the
 class files.
0
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.

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.



0
sankars98Commented:

 In your classpath , remove
 c:\mypackage\html; and try.
 I am not sure. It might be a problem.  
0
Ravindra76Commented:


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.


         

                   
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.