Deploying web application in Tomcat using Ant

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mjahabarsadiq
    New Member
    • Feb 2007
    • 38

    Deploying web application in Tomcat using Ant

    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_HO ME/work/standalone/localhost/onlineres.war".

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

    1) D:\Sadiq\Projec ts\Onlineres:
    This folder is having the context.xml, web.xml, build.xml and build.propertie s files.

    2) D:\Sadiq\Projec ts\Onlineres\sr c:
    This folder is having the java files

    3) D:\Sadiq\Projec ts\Onlineres\we b:
    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\Projec ts\Onlineres.

    1) D:\Sadiq\Projec ts\Onlineres\wa r\onlineres
    This folder is having the jsp pages, css and java scripts etc.

    2) D:\Sadiq\Projec ts\Onlineres\wa r\onlineres\WEB-INF
    This folder is having web.xml and all class files.

    3) D:\Sadiq\Projec ts\Onlineres\wa r\onlineres\MET A-INF
    This folder is having the context.xml file

    I have copied the D:\Sadiq\Projec ts\Onlineres\wa r\onlineres folder into "TOMCATE_HOME\w ebapps".

    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\Projec ts\Onlineres\wa r\onlineres. In this case the war file is not copied to "TOMCATE_HO ME/work/standalone/localhost/onlineres.war". Instead the application is running from the path "D:\Sadiq\Proje cts\Onlineres\w ar\onlineres.wa r". 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\Proje cts\Onlineres\w ar\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.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    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!
    Last edited by Dököll; Dec 6 '08, 06:08 PM. Reason: idea for diea :-)

    Comment

    • mjahabarsadiq
      New Member
      • Feb 2007
      • 38

      #3
      Explaining my problem in another view

      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
      Code:
      C:\Tomcat\Apache Group\Tomcat 4.1\
      I am having my web application in the following path
      Code:
      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.
      Code:
      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
      Code:
      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 "directorie s".
      Code:
          C:\Tomcat\Apache Group\Tomcat 4.1\webapps\tomcat-docs
          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.
      Code:
      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
      Code:
      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.
      Code:
      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.
      Code:
      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

      Code:
      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

      Comment

      • mjahabarsadiq
        New Member
        • Feb 2007
        • 38

        #4
        Is any one having solution for this problem?????


        by

        M. Jahabar Sadiq

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Why not include the files in that data folder inside the .war file itself.

          Comment

          • mjahabarsadiq
            New Member
            • Feb 2007
            • 38

            #6
            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

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              You can read and write to that directory from your servlets fine. You reference it relative to the application path using the getServletConte xt() 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.

              Comment

              • mjahabarsadiq
                New Member
                • Feb 2007
                • 38

                #8
                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.

                Comment

                • mjahabarsadiq
                  New Member
                  • Feb 2007
                  • 38

                  #9
                  Tried again and got the result partially.

                  Hi,

                  I have tried in the following way.

                  1) Copied the "onlineres. war" file in the following path
                  Code:
                  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.
                  Code:
                  http://localhost:8888/onlineres/index.jsp
                  By doing so I got the following errors in the log

                  Code:
                  2008-12-15 22:56:31 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
                  org.apache.jasper.JasperException
                  	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
                  	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
                  	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
                  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                  	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
                  	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
                  	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
                  	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
                  	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
                  	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
                  	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
                  	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
                  	at java.lang.Thread.run(Thread.java:534)
                  ----- Root Cause -----
                  java.lang.NullPointerException
                  	at org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
                  	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
                  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                  	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
                  	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
                  	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
                  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                  	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
                  	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
                  	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
                  	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
                  	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
                  	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
                  	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
                  	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
                  	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
                  	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
                  	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
                  	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
                  	at java.lang.Thread.run(Thread.java:534)
                  I suspect this error is due to the use of the following line in "index.jsp"
                  Code:
                  	InitialContext ctx = new InitialContext();
                  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.

                  Code:
                  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.

                  Code:
                  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.

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    That line is not the cause of the exception. If you read your exception trace, you'll see that a NullpointerExce ption was thrown. That line doesn't throw a NullpointerExce ption. Post your JSP code.

                    Comment

                    • mjahabarsadiq
                      New Member
                      • Feb 2007
                      • 38

                      #11
                      All codes are available in the zip file attached...

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        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.

                        Comment

                        Working...