aspose file tools*
The moose likes Struts and the fly likes Getting error while compiling Java File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting error while compiling Java File" Watch "Getting error while compiling Java File" New topic
Author

Getting error while compiling Java File

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi All,

I have following directory structure.


\WebContent\WEB-INF\classes\com\kogent\User.class
\WebContent\WEB-INF\src\com\kogent\User.java
\WebContent\WEB-INF\classes\com\kogent\Agent\GetUserAction.java

Below is the source for GetUserAction.java




When i tried to compile above java file i got following error.

Cannot find symbol
class User.


I know that above error is very simple and i tried all possible ways to eliminate it.
But could not succeed.

Could anyone please help me.

Thanks in Advance.
Jay.


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The package declaration in your action source doesn't match where it is in your directory hierarchy.

Without knowing the classpath you're using to compile it's impossible to help anyway.

Why are you getting a request parameter from the HttpServletRequest? Is there a reason you're not using the built-in functionality of Struts 2?
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi David,

Thanks for reply.

This is just a example source given in Struts Black Book. Moreover i am getting parameter using HttpServletRequest because it shows how to use ServletRequestAware Interface using this example.

Below is the classpath:

%CLASSPATH%;D:\Eclipse_wrksp\Struts2Application\WebContent\WEB-INF\lib\struts2-core-2.0.11.1.jar;D:\Eclipse_wrksp\Struts2Application\WebContent\WEB-INF\lib\xwork-2.0.1.jar


Thanks.
Jay
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, the package doesn't match. Are you compiling inside an IDE, or outside? What's in the %CLASSPATH% environment variable? With the incomplete information given I'm going to assume you're not including /WEB-INF/classes on the classpath, hence it can't find the class in question.
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi David,

Thanks for reply.

GetUserAction is under com/kogent/action folder.
Moreover when i did echo %CLASSPATH% word %CLASSPATH% is being displayed in at the beginning of the CLASSPATH.
I am compiling code outside IDE as somehow (not sure why) IDE is not able to compile code automatically.
However i added /WEB-INF/classes in classpath and tried to compile it.
Now i am getting error related to HttpServletRequest.

Cannot Find Symbol
Symbol: class HttpServletRequest

But i have added servlet.jar in build path as well as in CLASSPATH. This jar is also present in the lib folder.

Not sure why is this coming.

Thanks.
Jay.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It seems like you're trying things at random.

> GetUserAction is under com/kogent/action folder.

That's not what your original post said--it'll take longer if the information provided isn't accurate.

> Moreover when i did echo %CLASSPATH% word %CLASSPATH% is being displayed in at the beginning of the CLASSPATH.

What OS are you using?

> But i have added servlet.jar in build path as well as in CLASSPATH. This jar is also present in the lib folder.

I find that unlikely, otherwise it wouldn't be showing up as not found. It should *not* be present in your WEB-INF/lib folder, if that's what you mean.

Give the *EXACT* command you're using to compile, the *EXACT* contents of the CLASSPATH variable (the setting of which, by the way, usually causes more trouble than is worth).
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi David,

Hey Just now i am able to compile GetUserAction.java class. Because servlet.jar files location was not proper in classpath.

Thanks for your suggestions and moreover i will consider all your advices and try to put accurate information from first post itself.

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting error while compiling Java File