aspose file tools*
The moose likes Servlets and the fly likes classpath issue? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "classpath issue?" Watch "classpath issue?" New topic
Author

classpath issue?

Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
i have this problem....i'm not sure it is classpath issue or what, BUT im sure that my path is correct....please check it for me...thanks

it give me this error when i compile the servlet "BeerSelect.java".


BeerExpert.java
--------------------------------


BeerSelect.java
------------------

---------------------
here is my classpath:
---------------------
servlet-api.jar = C:\Tomcat_5.5\common\lib

BeerSelect.java = C:\MyProjects\beerV1\src\com\example\web

BeerExpert.java = C:\MyProjects\beerV1\src\com\example\model

when i compile:
-------------------------------------
C:\MyProjects\beerV1> javac -classpath /Tomcat_5.5/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java
-------------------------------------

and it give me "package does not exist" as above mentioned. haiz...where is my classpath wrong???

what is the solution???

please give me an idea....i try to fix this problem for 2 days already....


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Your src directory is not on the classpath.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yep, just to expand a little...

By compiling like this:
... classes src/com/example/web/BeerSelect.java
the package create is src.com.example.web and this is not what you want.
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi

so when i compile, it looks like this

C:\MyProjects\beerV1\src\ > ...-d classes com/example/web/SelectBeer.java

???
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm not 100% sure since I haven't read the book. this may be better:

Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
same result, still saying "package com.example.model does not exist."

Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
Try this:

1. Compile the model this way from src folder:
javac -d ../classes com/example/model/BeerExpert.java
This will create a folder called classes in the parent directory of src (..) and put com.example.model.BeerSelect class file in that package structure in the created classes directory.

2. Compile the servlet this way from src folder:
javac -classpath /Tomcat_5.5/common/lib/servlet-api.jar -classpath ../classes -d ../classes com/example/web/BeerSelect.java

3. Copy the contents of the classes folder to <your_application_in_server>/WEB-INF/classes folder.

4. When you register this servlet in web.xml, do not forget the full qualified class name (including the package structure)


keep smilin :: sravan<br /><a href="http://sravanpens.blogspot.com" target="_blank" rel="nofollow">I scribble here</a>
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
If the first step does not create a folder named classes, manually create one in the parent directory of src folder before trying these steps.
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi Sravan,

i did as you said from step 1 and 2. but step 3 when i compile using exactly what you said, it gave me error like "package javax.servlet does not exist" and the rest of javax.servlet and javax.servlet.http also no exist.

gosh, once this problem not fix, i hardly to continue to chapter 5 of HFSJ.
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
Step 3 is only a copy-paste operation to migrate from development to deployment. There is no compilation involved there.

1. Were your packages (com.example.model and com.example.web) recognized when you tried to compile in steps 1 and 2?

2. Try setting the system CLASSPATH to point to servlet-api.jar instead of passing it as an option with javac.
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi Sravan,

i know where is the problem already...gosh, i used 2 hours just now to find the wrong path....

my all path of each file and classes did not wrong. i was wrong at this:

C:\MyProjects\beerV1\ > javac -classpath /Tomcat_5.5/common/lib/servlet-api.jar;classes; -d classes src/com/example/web/BeerSelect.java

i forgot to put that BOLD word into the command line....i was such a noob b4.

thanks all for replying. Problem fixed.
xavi pedros
Greenhorn

Joined: Jul 11, 2009
Posts: 2
Hi everyone,

I have the same problem as Nicky, I have the system CLASSPATH set to point servlet-api.jar so when I compile I just put javac -d src/com/example/web/BeerSelect.java

How can I introduce the word ;classes; in the statement so I don't have to put the whole path everytime? I'm trying different statements but I still get 'package com.example.model does not exist'
I also tried: javac -classpath servlet-api.jar;classes; -d classes src/com/example/web/BeerSelect.java but then it doesn't find the javax packages too.

Thanks for the help
xavi pedros
Greenhorn

Joined: Jul 11, 2009
Posts: 2
In my CLASSPATH I got the following:
- D:\java
- C:\...\lib\servlet-api.jar

And my two Java files are here:

- d:\java\servlets\MyProjects\beerV1\src\com\example\web\BeerSelect.java
- d:\java\servlets\MyProjects\beerV1\src\com\example\model\BeerExpert.java

The classes are created there:

- d:\java\servlets\MyProjects\beerV1\classes\com\example\web\BeerSelect.class
- d:\java\servlets\MyProjects\beerV1\classes\com\example\model\BeerExpert.class

I compiled the BeerExpert.java like this:

- javac -classpath servlet-api.jar;classes; -d classes src/com/example/model/BeerExpert.java

And that seems to be ok since no error is shown. But now I'm not able to compile the other class, I tried different things and none runs properly.

EDIT:
The BeerSelect.java have this statement: "import com.example.model.*;" and I get the following error: 'package com.example.model does not exist'

I hope I gave enough information to help me solve the problem. Thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath issue?