By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,963 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

Deploying web application in Tomcat using Ant

P: 38
Hi

I have created a web application. I am using ant to build the war and deploy in tomcat.

The war file is deployed under "TOMCATE_HOME/work/standalone/localhost/onlineres.war".

I have my source files in "D:\Sadiq\Projects\Onlineres". The folder structure is as follows.

1) D:\Sadiq\Projects\Onlineres:
This folder is having the context.xml, web.xml, build.xml and build.properties files.

2) D:\Sadiq\Projects\Onlineres\src:
This folder is having the java files

3) D:\Sadiq\Projects\Onlineres\web:
This folder is having the jsp pages, css and java scripts.

After executing the build target in build.xml file, the following folders have been included in D:\Sadiq\Projects\Onlineres.

1) D:\Sadiq\Projects\Onlineres\war\onlineres
This folder is having the jsp pages, css and java scripts etc.

2) D:\Sadiq\Projects\Onlineres\war\onlineres\WEB-INF
This folder is having web.xml and all class files.

3) D:\Sadiq\Projects\Onlineres\war\onlineres\META-INF
This folder is having the context.xml file

I have copied the D:\Sadiq\Projects\Onlineres\war\onlineres folder into "TOMCATE_HOME\webapps".

Now after restarting the server, I try to access the application by the URL "http://localhost:8888/onlineres/index.jsp". Now I got the page not found error. (Note: I have configured the port as 8888 while installing the tomcat)

But I deploy the application using ant, I am able to access the application by the above said URL

Also I have tried using the install target. In this case the "onlineres.war" file is created within the D:\Sadiq\Projects\Onlineres\war\onlineres. In this case the war file is not copied to "TOMCATE_HOME/work/standalone/localhost/onlineres.war". Instead the application is running from the path "D:\Sadiq\Projects\Onlineres\war\onlineres.war ". But once I restarted the application the I am unable to access the application.

What I want to do is as follows.

I would like to run the application without creating the file "onlineres.war". I have the folder "D:\Sadiq\Projects\Onlineres\war\onlineres" after the build target in build.xml is executed using ant. I would like to run the application from this folder.

Whether this is possible? If so what I have to change? Please help.

Thanks in advance.
M. Jahabar Sadiq.
Dec 6 '08 #1
Share this Question
Share on Google+
11 Replies


Dököll
Expert 100+
P: 2,364
Hey there!

I feel your pain; for I have had similar problems with Tomcat... After deployment though, you would no longer need localhost. I believe you would need your production application server name.

I would try to not package into a war file and using you computer name, as test to see if your web app interacts properly with your files:

(1) Right-Click My Computer
(2) Go to properties
(3) Find computer name
(4) Replace localhost in your app with that name
(5) Open a new web browser
(6) Paste the entire address in

Thus:

http://YourComputerName:YourPortNumb...ppName.jsp(jsf)

This would give you an idea what errors, if any, exist upon deploying to Production App Server.

Note: you may need to disable your firewall for this to work...

Give that a whirl, see what happens.

Do stay tuned if this does not do it:-)

In a bit!
Dec 6 '08 #2

P: 38
Hi,

Here I am giving my problem in another view.

I am using ant to deploy the application in Tomcat 4.1 (Though this is the older version, I am using it).

I have installed the tomcat in the following path
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\
I am having my web application in the following path
Expand|Select|Wrap|Line Numbers
  1. D:\sadiq\Projects\jsp_web\OnlineRes
I have attached the
OnlineRes.zip
file of the above said web application folder.

When I called the deploy target in the build.xml file I got the following as the output.

1) The application is getting deployed into the following directory.
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\work\Standalone\localhost\manager\onlineres.war

2) Also the context entries have been added in the server.xml file in the following directory
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\conf
In the above case the war is not getting unpacked. The application is running from that ".war" file. We can see this by calling the "list" target. But other applications like "tomcat-docs" and "web-adv" are running from the following "directories".
Expand|Select|Wrap|Line Numbers
  1.     C:\Tomcat\Apache Group\Tomcat 4.1\webapps\tomcat-docs
  2.     C:\Tomcat\Apache Group\Tomcat 4.1\webapps\webadv

I have tried the following also without using the deploy task.

1) Copied the war file into the following directory manually.
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\webapps
2) Restarted the servers.
Now the war file is getting unpacked. But the context entries are not getting added to the server.xml file in the following directory
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\conf
I have to manually do this before restarting the server.



Please help me to get the following.

1) When I trigger the deploy target, the war file should get copied into the following directory.
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\webapps
2) The context entry should get added in the server.xml file in the following path after the deploy target is called.
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\conf
If I got the above said results, the war file will get unpacked when restarting the servers. Why I would like to unpack is, I will copy some files into the data directory within the application directory. That is in the following directory if the war is unpacked

Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\webapps\onlineres\data
The files inside this folder will be accesed via the jsp or servlet files and the data can be processed. [Source code for this has not been written yet]

Thanks in advance,
M. Jahabar Sadiq
Attached Files
File Type: zip OnlineRes.zip (9.0 KB, 121 views)
Dec 13 '08 #3

P: 38
Is any one having solution for this problem?????


by

M. Jahabar Sadiq
Dec 15 '08 #4

10K+
P: 13,264
Why not include the files in that data folder inside the .war file itself.
Dec 15 '08 #5

P: 38
The data in the files inside the data folder are the inputs to be processed and as the result some records will be created in the database whenever user wants to do so.

I would like to change the data in those files dynamically. So that we can create, update records. For this we need to write code separately. I hope I can do those coding, if I am able to modify the data in the files.

To do so, I need the war to be unpacked and so we can able to modify the data of the files within the data directory
Dec 15 '08 #6

10K+
P: 13,264
You can read and write to that directory from your servlets fine. You reference it relative to the application path using the getServletContext() method. war files are automatically unpacked by tomcat on every deploy anyway. Just include that folder as part of the war. It will be made available when the application is deployed.
Dec 15 '08 #7

P: 38
Thanks for your ideas..

I agree that we can read/write files in the data folder using servlet.

Why I would like to do so is as follows.

I would like to have some classes that will be run using some ant targets (we can call these classes as Loaders; because these classes are going to load the data from the files to the DB).

We can also run these classes from the UI. In this case I have no problem. As because I would like to run from ant, I would like to unpack the war.
Dec 15 '08 #8

P: 38
Hi,

I have tried in the following way.

1) Copied the "onlineres.war" file in the following path
Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\webapps
2) I have also copied the "onlineres.xml" file in the above said path. This file is having the context entries.
3) Restarted the servers.
But I didn't get the war unpacked. But if I omit the Step-2, I got the following result.

1) The "onlineres.war" file get unpacked into the directory "onlineres" while starting the servers.
2) The startup servlets are getting loaded successfully.
3) I tried accessing the "index.jsp" using the following URL.
Expand|Select|Wrap|Line Numbers
  1. http://localhost:8888/onlineres/index.jsp
By doing so I got the following errors in the log

Expand|Select|Wrap|Line Numbers
  1. 2008-12-15 22:56:31 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
  2. org.apache.jasper.JasperException
  3.     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
  4.     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  5.     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  6.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  7.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
  8.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
  9.     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
  10.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  11.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  12.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  13.     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  14.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  15.     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
  16.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  17.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  18.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  19.     at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
  20.     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
  21.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  22.     at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
  23.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  24.     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
  25.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  26.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  27.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  28.     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
  29.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  30.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  31.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  32.     at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
  33.     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
  34.     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
  35.     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
  36.     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
  37.     at java.lang.Thread.run(Thread.java:534)
  38. ----- Root Cause -----
  39. java.lang.NullPointerException
  40.     at org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
  41.     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
  42.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  43.     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
  44.     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  45.     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  46.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  47.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
  48.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
  49.     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
  50.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  51.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  52.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  53.     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  54.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  55.     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
  56.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  57.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  58.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  59.     at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
  60.     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
  61.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  62.     at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
  63.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  64.     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
  65.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  66.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  67.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  68.     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
  69.     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  70.     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  71.     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  72.     at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
  73.     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
  74.     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
  75.     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
  76.     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
  77.     at java.lang.Thread.run(Thread.java:534)
  78.  
I suspect this error is due to the use of the following line in "index.jsp"
Expand|Select|Wrap|Line Numbers
  1.     InitialContext ctx = new InitialContext();
  2.  
I have also tried by putting this in a try-catch block. Again I got the same result.

After I got this error now I copied the "onlineres.xml" file into the the following directory.

Expand|Select|Wrap|Line Numbers
  1. C:\Tomcat\Apache Group\Tomcat 4.1\webapps
Now I restarted the servers, the start up servlets are getting loaded.

Again I accessed the index.jsp file using the following URL.

Expand|Select|Wrap|Line Numbers
  1. http://localhost:8888/onlineres/index.jsp
I got the result as expected. The page is getting displayed correctly.

I have the problem if I put the "onlineres.xml" file before restarting the server once after dropping the "onlineres.war" file. Why this is happening.

I think it is not good to restart the servers two times, one for unpacking the wars, and one after placing the "onlineres.xml" - the context file.

Please give me a solution.


Thanks in advance.

M. Jahabar Sadiq.
Dec 15 '08 #9

10K+
P: 13,264
That line is not the cause of the exception. If you read your exception trace, you'll see that a NullpointerException was thrown. That line doesn't throw a NullpointerException. Post your JSP code.
Dec 17 '08 #10

P: 38
All codes are available in the zip file attached...
Dec 17 '08 #11

10K+
P: 13,264
I don't like downloading zip attachments form the forums. Like I said the nullpointer is in your index.jsp. Somewhere there (probably in the first few lines that use use Java code) you are dereferencing a null variable.
Dec 17 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.