aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes javac compile import package BeerSelect.java:3: error: package com.example.model does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "javac compile import package BeerSelect.java:3: error: package com.example.model does not exist" Watch "javac compile import package BeerSelect.java:3: error: package com.example.model does not exist" New topic
Author

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

jing ma
Greenhorn

Joined: Jun 22, 2011
Posts: 10
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 BeerSelect.java source file is in C:\Users\myname\Documents\JSP\MyProject\beerV1\src\com\example\web
the BeerExpert.java source file is in C:\Users\myname\Documents\JSP\MyProject\beerV1\src\com\example\model

the code of BeerSelect.java


the code of BeerExpert.java 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 BeerExpert.java
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 BeerSelect.java it can not import package com.example.model.BeerExpert.class Here is my commandline to compile BeerSelect.java
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 BeerExpert.java




Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

Hi

Try to follow these instructions: HowToCreateWebApplicationWithoutAnIDE.

Regards,
Frits
Ryan Wilson
Ranch Hand

Joined: Apr 16, 2003
Posts: 65
Try:

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\BeerExpert.java

The separator for the classPath on windows is ';' you had a ':'
jimme van der meer
Greenhorn

Joined: Nov 15, 2013
Posts: 2
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 BeerSelect.java 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac compile import package BeerSelect.java:3: error: package com.example.model does not exist