Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

javac compile import package error: package com.example.model does not exist

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on the Head Servlet&JSP book projects. I can not recognize import packages and can not compile.
can anyone so kindly help me about this? I google online about the classpath. but I might misunderstand it. Please help me about this Thanks!

There is a problem about javac compiling. Here is my development directory structure
project directory C:\Users\myname\Documents\JSP\MyProject\beerV1
under beerV1 I followed the book,
the source file is in C:\Users\myname\Documents\JSP\MyProject\beerV1\src\com\example\web
the source file is in C:\Users\myname\Documents\JSP\MyProject\beerV1\src\com\example\model

the code of

the code of compiled with commandline under windows7:
C:\Users\myname\Documents\JSP\MyProject\beerV1\src\com\example\model> javac -classpath C:\tools\tomcat\lib\servlet-api.jar -d C:\Users\myname\Documents\JSP\MyProject\beerV1\classes
it comiled and generated the BeerExpert.class under directory C:\Users\myname\Documents\JSP\MyProject\beerV1\classes\com\example\model

when I try to compile the it can not import package com.example.model.BeerExpert.class Here is my commandline to compile
C:\Users\myname\Documents\JSP\MyProject\beerV1\src\com\example\web> javac -classpath C:\tools\tomcat\lib\servlet-api.jar; C:\Users\myname\Documents\JSP\MyProject\beerV1\classes\com\example\model\*.class:. -d C:\Users\myname\Documents\JSP\MyProject\beerV1\classes

Creator of Enthuware JWS+ V6
Posts: 3341
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Try to follow these instructions: HowToCreateWebApplicationWithoutAnIDE.

Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

C:\Users\myname\Documents\JSP\MyProject\beerV1> javac -classpath C:\tools\tomcat\lib\servlet-api.jar;classes;. -d C:\Users\myname\Documents\JSP\MyProject\beerV1\classes src\com\example\web\

The separator for the classPath on windows is ';' you had a ':'
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the people that still run into the same problem, just like me today... There is an even easier solution:

- make a new class in eclipse with the exact same package and class name.
- save the class in eclipse and locate it in your eclipse workspace which was for me C:\Users\VDM\Desktop\workspaceLaptop\DemoJSP\build\classes\com\example\web\BeerSelect.class
- copy that class to your deployment environment for me C:\apache-tomcat-7.0.47\webapps\Beer-v1\WEB-INF\classes\com\example\web

And you're done.. The cool thing about eclipse is that it automatically compiles the .java to .class for you without these (complicated) cmd commands.
You can probably do it with any java compiler that automatically generates .class files, just make sure you use the same package and class name as they ask in the book
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic