Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Tomcat not loading its servlet jars to classpath at run time  RSS feed

 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm trying to write a very basic web application in java ee6. I'm using Tomcat 8.0.36 version & this is my configuration of environment variables.

  
Then I created a simple web application with the following directory structure:

   

My java source is in src\com\dhaka\controller\AddCalcServlet.java  :



And web.xml :

  


1. First I tried to create war file by following, but the .class file of the servlet was not created:

  

2. Then I tried to build project by ant, but I the following error:
  



3. Then I tried to create .class file byI compiling the servlet class by appending the jar manually to the classpath:

   
   
    And I got the response:
   
 

The server was started using startup.bat. This is the document trace which i got when I run the server I ran the server by:



What should I do in order to run the web app in tomcat? I'm new to java ee, I apologize if I did any silly mistake.

Regards
Joeyaris



 
Dave Tolls
Ranch Hand
Posts: 2504
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, don't do your development in the tomcat directory.
You should be deploying a complete webapp into there and not actually doing your dev work there.
I suspect this is the root of your compilation issues.

So move all the stuff from src on down out of there into some other dev directory for your app.

The next thing is to decide what it is you want to achieve with this.
Do you want a war file, or just a structured build directory you can drop into Tomcat?
Do you want to learn and use Ant?
Or something else?
 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave. I actually developed the web app in a development folder and then deployed it in tomcat. For some reason, the servlet.class files are not being generated. I tried in 3 different ways to generate class files. None of them was succeeded. At least, the 3rd step should work since i tried by appending servlet jar file manually. I tried to use ant just to generate project war file. For some reason, generated war file does not include servlet.class file. Any idea?

Regards
JoeYaris
 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer to generate war file and then deploy it in tomcat by simply adding it in tomcat/webapp directory.

Regards
JoeYaris
 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since generated war file by ant didn't include  java class files, that's why I tried to generate them manually and it also didn't work.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be setting any env variable except JAVA_HOME. Tomcat sets its own environment variable(s), and why did you put a jar file in the PATH?
 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear Bibeault, I deleted the servlet jar from path of env variable and then tried to compile, but getting the following error. I'm lost and no clue what is the issue just to compile the the servlet file manually by appending jar file.

 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, the error is as follows:








 
Dave Tolls
Ranch Hand
Posts: 2504
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the %CATALINA_HOME%\lib\servlet-api.jar file.
They're just zip files in disguise, so you should be able to open it and look to see what's in there.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PATH has nothing to do with compiling. Are you confusing it with the class path?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!