This discussion is archived
4 Replies Latest reply: Jul 11, 2013 12:58 PM by 1013536 RSS

Not able to export file as .war to webapps in tomcat home

1013536 Newbie
Currently Being Moderated

Below is my first servlet program:

FirstServlet.java:

 

package edu.aspire;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.Servlet;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

 

 

public class FirstServlet implements Servlet {

  static {

  System.out.println("Loading Servlet");

  }

 

 

  public FirstServlet() {

  System.out.println("Instantiating Servlet");

  }

 

 

  public void init(ServletConfig config) throws ServletException {

  System.out.println("Initializing Servlet");

  }

 

 

  public void destroy() {

  System.out.println("Removing Servlet from the Servlet container");

  }

 

 

  public ServletConfig getServletConfig() {

  return null;

  }

 

 

  public String getServletInfo() {

  return null;

  }

 

 

  public void service(ServletRequest request, ServletResponse response)

  throws ServletException, IOException {

  System.out.println("service() method");

  PrintWriter out = response.getWriter();

  out.println("Hello World!");

  }

}

 

web.xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <servlet>

    <servlet-name>aspire</servlet-name>

    <servlet-class>edu.aspire.FirstServlet</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>aspire</servlet-name>

    <url-pattern>/first</url-pattern>

  </servlet-mapping>

</web-app>

 

Deployement:

To deploy my project into %TOMCAT_HOME%\webapps folder.

Right click on Project ->Export-> War File

Project Name: Hello

Destination: D:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\Hello.war

 

Result found in web browser:

HTTP Status 404 - /Hello/first

 

And Hello.war file is not found in webapps folder too after exporting as .war.

I am using Apache tomcat 6.0.37, eclipse 3.7.2 release, tomcat plugin :com.sysdeo.eclipse.tomcat_3.3.0

Please let me know where i am going wrong.

  • 1. Re: Not able to export file as .war to webapps in tomcat home
    gimbal2 Guru
    Currently Being Moderated

    In stead of manually exporting a war you should look into setting up a server runtime in Eclipse and using the built-in deployment features; once you have your project's deployment assembly properly setup it is automatic. A Google for "Eclipse tomcat runtime" will probably lead you to a proper example eventually.

  • 2. Re: Not able to export file as .war to webapps in tomcat home
    1013536 Newbie
    Currently Being Moderated

    I dont know to do automatic settings. Which site will guide me?... Can u help me out

  • 3. Re: Not able to export file as .war to webapps in tomcat home
    gimbal2 Guru
    Currently Being Moderated

    Read the entire post, not just the first sentence. I repeat myself:

     

    A Google for "Eclipse tomcat runtime" will probably lead you to a proper example eventually.

  • 4. Re: Not able to export file as .war to webapps in tomcat home
    1013536 Newbie
    Currently Being Moderated

    I have done all those settings but still read the 'Eclipse tomcat run time' and repeated the settings accordingly. Still not not getting output.

    -I exported the file to destination webapps folder and clicked 'finish'

    -when i select 'run on server'

    -the tomcat gets started and 'http status 404' page is displayed in browser

     

    I even tried this

    - manaully started server

    -exported as .war file to webapps but  does not get exported, doesnt get deployed and nothing gets displayed in the console

    -when provide the link the same page is displayed


    One alert message is displayed in the markers 'Classpath entry C:/Program Files/Apache Software Foundation/Tomcat 6.0/lib/servlet-api.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.'

    I have added servlet-api.jar to the library but still getting this message so tried to adding in classpath (as provided in websites) that also didnt work.

     

    Next what to do i dont understand.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points