Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do i import a compiled file in current file

 
roomy iqbal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks guys you have been very helpful in last problem now i have got another problem. I have got 2 files Book.java and ShoppingServlet.java. I have compiled Book.java and it has generated a class file. Shopping sevlet uses Book.java items. here is how the code looks like

Book.java


ShoppingServlet.java


Now when I execute this it gives me errors related to Book.java which is already compiled and its class file is available. I have tried to put it in -cp parameter as well here is the kind of error i get

 
Campbell Ritchie
Sheriff
Posts: 48396
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to find where the Book class is. Are you used to compiling classes with a package declaration?

If you search through beginners' you find old threads.
  • This one, where somebody else seems to have the same problem.
  • This one where the late Stan James (instanceof SideKick) links to a tutorial about packages.
  • Somebody who had a very simple answer to compiling two files.
  • At least two ways to compile files in packages.

  • Make sure you have the servlet packages installed. Try compiling both files simnultaneously. Tell us whether it worked.
     
    Ernest Friedman-Hill
    author and iconoclast
    Marshal
    Pie
    Posts: 24208
    35
    Chrome Eclipse IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Also note that within a package "ebookshop", it is not not only unnecessary to import any other class in package ebookshop, but in fact it might be part of the problem you're having. The import statement doesn't belong there at all.
     
    roomy iqbal
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks i managed to fix it using the links that you guys provided. I just compiled them together and it worked

    javac -Xlint Book.java SoppingServlet.java
     
    Campbell Ritchie
    Sheriff
    Posts: 48396
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well done
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic