Installing and configurating Apache Tomcat 5.5 and 6.x. (Windows and Linux)

October 24th, 2007  | Tags:

Hi There,

After a long time far away from this blog, I am here to write about Apache Tomcat.

Although this topic is simple for many people, it may be useful for whom is starting in Java Web World.

I am writing this topic because I have seen many people on Java’s forum and also some friends newbie in Java asking for this issue. Besides the basic, I am going to talk about management and datasource configuration in Apache Tomcat, as well as a Java code example to use the tomcat’s datasource.

Downloading the proper version

The Tomcat’s official website is that: http://tomcat.apache.org/. There you are going to see all information about Tomcat, as well as the version to be downloaded. If you are newbie in tomcat and would like to get more information than wrote in this topic, I encourage you to spend some time in Tomcat’s official website.

The first thing to do is download the proper version. In nowdays, basically we have two updated version: 5.5 and 6.x. What’s the difference between them?

In general speaking, the difference between them is the JEE version used. Tomcat version 6.x uses JEE 5.0 (Servlet 2.5, JSP 2.1) and Tomcat version 5.5 uses JEE 1.4 (Servlet 2.4, JSP 2.0).

If you are going to work on JEE 5.0, you must download the tomcat 6.x, otherwise you can download version 5.5. In this topic, I am going to explain how to configure both versions.

Whatever version you choose, you are going to see on download page three files (.zip, .tar.gz, Windows Service Installer). If you are installing the Tomcat in an Unix-like system, you must download the version .tar.gz. If you are installing the Tomcat in a Windows system, you can choose either .zip or Windows Service Installer file. In my opinion, I prefer the .zip file.

Installing Tomcat

In this section, let’s talk about Tomcat installation. Fortunately the installation in both Windows and Linux system is really easy.

Basically, you have to unzip the tomcat installation file and after create two environment variables. Also, you have to make sure if the JAVA_HOME environment variable is already set.

Windows Installation

Firstly, you have to unzip the Tomcat installation file in any directory. Let’s use as example the tomcat’s version 5.5.25 (for tomcat’s version 6.x, the process is exactly the same) and the directory “Programs Files“. Unzipping the tomcat’s file inside Programs Files directory, a new directory will be created, called “apache-tomcat-5.5.25“.

Now, the next step is to create two environment variables. In Windows, just click on Start button -> Settings -> Control Panel.

On the Control Panel screen, double click on System icon. A new window will be opened.

In this new window (System Properties), click on Advanced tab and after on Environment Variables button.

An Environment Variables window will be opened.

On the bottom of this window, there are some System variables such as: CLASSPATH, INCLUDE, LIB, etc. You have to create more two variables: CATALINA_HOME and CATALINA_BASE.

Click on New button and a new window will appear.

In this new window, you have to fill up both fields: Variable name and variable value.

Put the following information in these fields:
Variable name: CATALINA_HOME
Variable value: <path of Tomcat apache> in my example would be: C:\Program Files\apache-tomcat-5.5.25

Repeat the same process but putting the variable name: CATALINA_BASE and the variable value the same than CATALINA_HOME.

Before close up the Environment Variables window, make sure the JAVA_HOME is set up. If not, you must configure the JAVA_HOME (like CATALINA_HOME) but referring the path where Java was installed.

After the environment variables were defined, you will be able to start Tomcat. Simply perform the file startup.bat (it is localized inside tomcat/bin directory). A command prompt window will appear and show you the starting. If the following screen appears, your tomcat has been installed successfully.

If you got any exception on startup, try to repeat the installation process again.

Unix/Linux installation

The process in Unix/Linux is similar than Windows. Basically you have to uncompress the .tar.gz file and create two environment variables.

To uncompress the .tar.gz file in Unix/Linux system, you can use the command tar.An example would be:

tar -zxvf apache-tomcat-5.5.25.tar.gz

This command will uncompress the file apache-tomcat-5.5.25.tar.gz and also will create a directory called apache-tomcat-5.5.25. This is the directory where tomcat was installed in Linux. I advice you to use a directory where your current user has access to read/write files.

The next step, like in Windows, is create the environment variables. In Linux, you can create these variables editing the file .profile inside your home directory.

Edit this file and add the following lines:

export CATALINA_HOME="<directory where tomcat was installed>". eg: "/home/junior/apache-tomcat-5.5.25"
export CATALINA_BASE="<directory where tomcat was installed>"

Like in Windows, you have to make sure the JAVA_HOME is set.

To start the Tomcat in Linux, you have to perform the file startup.sh. This file is localized inside apache-tomcat/bin directory. Also like windows, you will see the starting in console. Any exception, try to repeat the process.

Starting up, testing and shutting down

As described above, to start the tomcat, you simply have to perform startup.bat (Windows) or startup.sh (Unix/Linux). A window will show up if the process has been startup successfully.

After tomcat was startup, it is time to test it. It is also a simple task, only open your internet browser, and try the following URL: http://localhost:8080.

You should see a screen like this:

As you can see, by default tomcat runs on port: 8080. If you want to change this port, you have to modify the file server.xml inside apache-tomcat-5.5.25/conf directory and restart the tomcat server, but the question is: How can I restart the apache tomcat?

There is no option to restart the tomcat, you must shutdown it and after that start it again.

To shutdown it, you can either stop the current process (in windows just close the command prompt) or perform the file shutdown.bat (windows) or shutdown.sh (Linux).

Tomcat Manager

When you start the tomcat and open the default page (http://localhost:8080), you have an option called Tomcat Manager in the left menu.

Inside this section, you are able to deploy a new application, undeploy an existing application, stop or start a single application, reload a context and so on.

If you try to click on this Link, an Authentication pop up will appear. In other words, to access the Tomcat manager you have to put the proper user and password. Where can I figure out this user/password?

Whatever which version you are using and which operating system you are, you have to modify the file tomcat-users.xml. By default, it brings some examples, but you have to create your own rules, anything like this:

<tomcat-users>
  <role rolename="manager"/>
  <user username="test" password="test123" roles="manager"/>
</tomcat-users>

After this file is changed, stop and start the tomcat again.

Click on Tomcat Manager and when the popup appears, put test as username and test123 as password. If your data are correct, you are going to see the Manager screen.

On this screen you are able to start, stop, reload or undeploy an application. Also, you are able to deploy a new application located on server or upload a war file and deploy it. Fell free to click on options and see what will happen.

Deploying an application without Tomcat Manager

You already learned how to deploy a WAR file using Tomcat Manager, however you are free to deploy an application without it as well.

Inside apache-tomcat directory, there is a directory called “webapps“. All application deployed are localized in this directory.

You are able either to copy your application for this directory directly or copy your .war file inside it. When Tomcat starts, it will read this directory and make the deploy automatically.

Another option for deploying is to use an external tool. You can use ANT or MAVEN to make the deploy or use a plugin for Eclipse, such as: WTP, TomcatPlugin, MyEclipseIDE, etc.

Creating a DataSource in Apache Tomcat

In real applications, it is recommended to use a Connection Pool to management of your connection with database. Whatever application server you are using, you have to create a DataSource to use a connection pool. Each application server has a different way to create a DataSource. In this topic I am going to show you how to create it in Apache Tomcat (in the future I will write a post about DataSource in Websphere 6.0).

Fortunately in Apache Tomcat the process to create a DataSource is simple. Basically you have to create/modify a file called context.xml.

If you want a global datasource, it means a datasource will be eligable for all application, you have to modify the file context.xml localized in apache-tomcat-5.5.25/conf.

If you want a specific datasource, you have to create a context.xml file inside META-INF directory inside your own application. It means, the datasource will be eligable only for the current application.

The content of the context.xml file should be anything like this:

<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true">
     <Resource name="jdbc/TestDB"
                    auth="Container"type="javax.sql.DataSource"
                    maxActive="100"
                    maxIdle="30"
                    maxWait="10000"
                    username="username"
                    password="password"
                    driverClassName="driverClass"
                    url="URL"/>
</Context>

Besides it, you have to put the JARs files from your JDBC in the Tomcat’s classpath (not application’s classpath). It is also simple to do. Simply copy the required JAR files to apache-tomcat-5.5.25/common directory. Here there is a difference between Tomcat 5.5 and 6.x. In 6.x, the classpath directory is different. You have to copy the JARs to apache-tomcat-6.0/lib directory.

Setting up the web.xml file

Whatever application server you are working, you have to set up the web.xml file in the same way.

For our example, you have to add the following lines:

	<resource-ref>
		<res-ref-name>jdbc/TestDB</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

Accessing the DataSource in Java

After all, you have to implement a class to access the DataSource.

As expected, the DataSource must be located using JNDI. Below following an example in Java.

 	try {
                  InitialContext initial = new InitialContext();
                  Context context = (Context) initial.lookup("java:/comp/env");
                  DataSource ds = (DataSource) context.lookup("jdbc/TestDB");
                  Connection con = ds.getConnection();
        } catch (SQLException e) {
                  e.printStackTrace();
        } catch (NamingException e) {
                  e.printStackTrace();
 	}

The code above gets a connection from DataSource configured in Tomcat and store it to a java.sql.Connection object.

In this way, you are able to work with DataSource in your application.

I hope this topic is useful for everyone.

If you have any feedback, fell free to make a comment.

CYA.

  1. Mitch
    December 8th, 2007 at 02:17
    #1

    Hi,
    I am using apache and eclipse for the first time. I am running into an issue. When I create the HelloServlet.java class, a yellow icon with a question mark appears on top on my web-inf, package, and class. I also notice a yellow line appears under the class name HelloWorld. I place the curso on top of it, and I saw the message below:
    “The serializable class HelloServlet does not declare a static final serialVersionUID field of type long”. I am not sure what I did wrong. When I paste the url in the browser, it does not show the message. It shows me an error 404.
    I am using eclipse 3 with tomcat 6 and java 5.
    P.S. I started tomcat, and all the jsp and html samples are working fine.

  2. jrjuniorsp
    December 10th, 2007 at 11:19
    #2

    Hi Mitch,

    First of all, the “warning” message you got is common. It means the class serializable (all classes that extends HttpServlet are serializable) does not have a serialVersionUID. If you are using eclipse, you can add a versionUID clicking in the warning message.
    Try google to learn more about this features.
    About the error 404, it means the servlet has not been localized. I don’t know which plugin you are using (or even Eclipse Europa JEE), but try to create the servlet through the Servlet Wizard. Also, make sure the web.xml file is mapped properly, as well as it is localized into WEB-INF directory.
    Finally, make sure the tomcat is running properly (take a look at the initialization process and see if no errors is shown).
    This is a simple post to run the Tomcat, but you gave me an idea to write a post about how to run servlet in Tomcat using Eclipse and netbeans.

  3. December 17th, 2007 at 01:53
    #3

    jrjuniorsp,
    1. I am using Eclipse Europa V3.3.1.1, JDK 1.5, Sysdeo/SQLI Eclipse TomcatPluginV321.zip, and tomcat 6.
    2. I don’t know how to create the servlet using the servlet wizard (I didn’t even know they have a servlet wizard.)
    3. I am not sure how to map the web.xml file. I will post a copy bleow
    4. When I run the the servlet, I am getting an error saying that port 8080 is already in used. However, I don’t have anything that is using port 8080 beside tomcat. See error below

    Web.xml File: (it said -app and Microsystems is not spelled correctly.)

    hello
    HelloServlet

    hello
    /hello

    Error Message when run servlet

    Dec 16, 2007 8:35:56 PM org.apache.catalina.core.AprLifecycleListener init
    INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_01\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.5.0_01\bin\..\jre\bin\client;C:\Program Files\Java\jdk1.5.0_01\bin\..\jre\bin;C:\Program Files\Java\jdk1.5.0_01\bin;c:\Program Files\Microsoft SQL Server\90\Tools\binn;C:\ant\apache-ant-1.7.0\bin;C:\jdbc\sqljdbc_1.2\enu\sqljdbc.jar
    Dec 16, 2007 8:35:58 PM org.apache.coyote.http11.Http11Protocol init
    SEVERE: Error initializing endpoint
    java.net.BindException: Address already in use: JVM_Bind:8080
    at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:501)
    at org.apache.coyote.http11.Http11Protocol.init(Http11Protocol.java:177)
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1059)
    at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
    at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:792)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:518)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
    Dec 16, 2007 8:35:58 PM org.apache.catalina.startup.Catalina load
    SEVERE: Catalina.start
    LifecycleException: Protocol handler initialization failed: java.net.BindException: Address already in use: JVM_Bind:8080
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1061)
    at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
    at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:792)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:518)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
    Dec 16, 2007 8:35:58 PM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 11461 ms
    Dec 16, 2007 8:35:59 PM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Dec 16, 2007 8:35:59 PM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
    Dec 16, 2007 8:36:03 PM org.apache.tomcat.util.digester.Digester fatalError
    SEVERE: Parse Fatal Error at line 13 column 3: The element type “web-app” must be terminated by the matching end-tag “”.
    org.xml.sax.SAXParseException: The element type “web-app” must be terminated by the matching end-tag “”.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:215)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:386)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1438)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1219)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
    at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:369)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1062)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4239)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Dec 16, 2007 8:36:03 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
    SEVERE: Parse error in application web.xml file at jndi:/localhost/HelloWorld/WEB-INF/web.xml
    org.xml.sax.SAXParseException: The element type “web-app” must be terminated by the matching end-tag “”.
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1269)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
    at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:369)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1062)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4239)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Dec 16, 2007 8:36:03 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
    SEVERE: Occurred at line 13 column 3
    Dec 16, 2007 8:36:03 PM org.apache.catalina.startup.ContextConfig start
    SEVERE: Marking this application unavailable due to previous error(s)
    Dec 16, 2007 8:36:04 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error getConfigured
    Dec 16, 2007 8:36:04 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context [/HelloWorld] startup failed due to previous errors
    Dec 16, 2007 8:36:07 PM org.apache.coyote.http11.Http11Protocol start
    SEVERE: Error starting endpoint
    java.net.BindException: Address already in use: JVM_Bind:8080
    at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:501)
    at org.apache.tomcat.util.net.JIoEndpoint.start(JIoEndpoint.java:515)
    at org.apache.coyote.http11.Http11Protocol.start(Http11Protocol.java:204)
    at org.apache.catalina.connector.Connector.start(Connector.java:1132)
    at org.apache.catalina.core.StandardService.start(StandardService.java:531)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Dec 16, 2007 8:36:07 PM org.apache.catalina.startup.Catalina start
    SEVERE: Catalina.start:
    LifecycleException: service.getName(): “Catalina”; Protocol handler start failed: java.net.BindException: Address already in use: JVM_Bind:8080
    at org.apache.catalina.connector.Connector.start(Connector.java:1139)
    at org.apache.catalina.core.StandardService.start(StandardService.java:531)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Dec 16, 2007 8:36:07 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 8569 ms
    Dec 16, 2007 8:36:07 PM org.apache.catalina.core.StandardServer await
    SEVERE: StandardServer.await: create[8005]:
    java.net.BindException: Address already in use: JVM_Bind
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
    at java.net.ServerSocket.bind(ServerSocket.java:319)
    at java.net.ServerSocket.(ServerSocket.java:185)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:630)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:590)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Dec 16, 2007 8:36:07 PM org.apache.coyote.http11.Http11Protocol pause
    INFO: Pausing Coyote HTTP/1.1 on http-8080
    Dec 16, 2007 8:36:07 PM org.apache.catalina.connector.Connector pause
    SEVERE: Protocol handler pause failed
    java.lang.NullPointerException
    at org.apache.jk.server.JkMain.pause(JkMain.java:679)
    at org.apache.jk.server.JkCoyoteHandler.pause(JkCoyoteHandler.java:153)
    at org.apache.catalina.connector.Connector.pause(Connector.java:1074)
    at org.apache.catalina.core.StandardService.stop(StandardService.java:563)
    at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:616)
    at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:659)

  4. jrjuniorsp
    December 17th, 2007 at 13:14
    #4

    According to the error, the port 8080 is already used yes.
    Try to remove tomcat and install it again.

  5. December 18th, 2007 at 05:01
    #5

    Thank you jrjuniorsp,
    When I start tomcat, I click on start tomcat button at the top. It starts tomcat when I run the application, it starts tomcat again. That was the reason why I was getting the error message. I was able to see my Hello World First Servlet. I am now working on the Hello World JSP. HEHEHEHEHEHEHEHEHE thank you so much!

  6. December 20th, 2007 at 02:27
    #6

    Hi,
    I am new to servlet programming. I was searching online for jsp tutorial, and I found a website. However, I did not understand where to place the form that was created. Also, I did not understand where the parameters get the values that were printed. Can someone please tell me how they get the values and where to place the form?

    Please see the website an example of the servlet and the form below.

    http://javaboutique.internet.com/tutorials/JSP/part04/page03.html

    The servlet looks like this:

    package hall;

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;

    /** Shows all the parameters sent to the servlet via either
    * GET or POST. Specially marks parameters that have no values or
    * multiple values.
    *

    * Part of tutorial on servlets and JSP that appears at
    * http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
    * 1999 Marty Hall; may be freely used or adapted.
    */

    public class ShowParameters extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType(”text/html”);
    PrintWriter out = response.getWriter();
    String title = “Reading All Request Parameters”;
    out.println(ServletUtilities.headWithTitle(title) +
    “\n” +
    “” + title + “\n” +
    “\n” +
    “\n” +
    “Parameter NameParameter Value(s)”);
    Enumeration paramNames = request.getParameterNames();
    while(paramNames.hasMoreElements()) {
    String paramName = (String)paramNames.nextElement();
    out.println(”" + paramName + “\n”);
    String[] paramValues = request.getParameterValues(paramName);
    if (paramValues.length == 1) {
    String paramValue = paramValues[0];
    if (paramValue.length() == 0)
    out.print(”No Value”);
    else
    out.print(paramValue);
    } else {
    out.println(”");
    for(int i=0; i<paramValues.length; i++) {
    out.println(”" + paramValues[i]);
    }
    out.println(”");
    }
    }
    out.println(”\n”);
    } }

    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    }
    }

    and the forms looks like this

    A Sample FORM using POST

    A Sample FORM using POST

    Item Number:

    Quantity:

    Price Each:

    First Name:

    Last Name:

    Middle Initial:

    Shipping Address:

    Credit Card:
    Visa
    Master Card
    American Express
    Discover
    Java SmartCard
    Credit Card Number:

    Repeat Credit Card Number:

  7. gaj
    May 23rd, 2008 at 08:30
    #7

    “This release of Apache Tomcat was packaged to run on J2SE 5.0
    or later. It can be run on earlier JVMs by downloading and
    installing a compatibility package from the Apache Tomcat
    binary download page.” I am getting this error pls help me by solving this…..

  8. jrjuniorsp
    May 23rd, 2008 at 10:50
    #8

    Are you using JDK 5 ? If not, it is a good change to update your JDK :)

  9. September 5th, 2008 at 07:20
    #9

    hai…

    its really usefull information for me. thank u so much…

    regards
    prabu

  10. Daniel
    March 11th, 2009 at 19:55
    #10

    Olá Jair, apesar de ter seguido a risca a parte do DataSource, parece que não funcionou, me retorna o seguinte erro:
    Caused by: org.hibernate.HibernateException: Could not find datasource: java:comp/env/jdbc/ORACLE
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:82)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)

  11. March 14th, 2009 at 20:25
    #11

    Daniel,
    O DataSource não foi configurado corretamente. Só por essa mensagem não posso te ajudar, mas certamente é algo relacionamento com a configuração do DataSource.

  12. Roan
    October 7th, 2009 at 17:59
    #12

    tu ja viu esse erro? Esotu rodando pelo Maven build

    Oct 7, 2009 5:58:20 PM com.sun.jersey.server.impl.application.WebApplicationImpl mapMappableContainerException
    SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
    java.lang.NoClassDefFoundError: com/sun/appserv/jdbc/DataSource
    at com.citespace.citespacews.MyResource.getIt(MyResource.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:156)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:208)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:75)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:115)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:67)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:736)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:701)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:692)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:339)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:452)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:633)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.ClassNotFoundException: com.sun.appserv.jdbc.DataSource
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    … 30 more
    Oct 7, 2009 5:58:20 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet Jersey Web Application threw exception
    java.lang.ClassNotFoundException: com.sun.appserv.jdbc.DataSource

  13. October 7th, 2009 at 20:28
    #13

    Roan, a exception diz tudo: java.lang.NoClassDefFoundError: com/sun/appserv/jdbc/DataSource
    Está faltando JAR ai na sua lib

TOP