Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat - Exception when I try to share two projects on two different ports

Tags:

tomcat

I have two webservice a SOAP (Axis2) and the other type REST (Jersey 2).

Everything works fine, but I want to put one on port 8080 and one on port 8081.

I started edit my server.xml inside my tomcat/conf folder for create a new service with his own connector, engine and host like this :

server.xml :

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener SSLEngine="on"
    className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
    <Resource auth="Container" description="User database that can be updated and saved"
        factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase"
        pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase" />
</GlobalNamingResources>
<Service name="reciver">
    <Connector acceptCount="100" connectionTimeout="10000"
        disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192"
        maxThreads="10" port="8080" useBodyEncodingForURI="true" />
    <Engine defaultHost="localhost" jvmRoute="host1" name="reciver"> 
        <Host autoDeploy="true" name="localhost" unpackWARs="true">
            <Context docBase="SOAP" path="/SOAP" reloadable="true"
                source="org.eclipse.jst.jee.server:SOAP" />
        </Host>
    </Engine>
</Service>
<Service name="reciver2">
    <Connector acceptCount="100" connectionTimeout="10000"
        disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192"
        maxThreads="10" port="8081" useBodyEncodingForURI="true" />
    <Engine defaultHost="localhost" jvmRoute="host2" name="reciver2"> 
        <Host autoDeploy="true"  name="localhost" unpackWARs="true">
            <Context docBase="REST" path="/REST" reloadable="true"
                source="org.eclipse.jst.jee.server:REST" />
        </Host>
    </Engine>
</Service>

I have a problem with my context on the second Service. When i add this one and try to launch Tomcat i got this exception :

GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[reciver2].StandardHost[localhost].StandardContext[/REST]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[reciver2].StandardHost[localhost].StandardContext[/REST]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@5e8549c9]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4909)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5039)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.IllegalArgumentException: The main resource set specified [C:\DEV\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps\REST] is not valid
at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:723)
at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:684)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more

déc. 09, 2015 11:23:28 AM org.apache.catalina.core.ContainerBase startInternal
GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[reciver2].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[reciver2].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more

déc. 09, 2015 11:23:28 AM org.apache.catalina.startup.Catalina start
GRAVE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[reciver2]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[reciver2]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more

When i delete the context tomcat launch and listen on this port.

port

This is the first time i try to do that, I'm doing something wrong, but I do not know where I search on google and stack but I have not found the solution.

I working on windows 10, tomcat 8 and eclipse Mars.

If one of you knows the solution I will be grateful to him for help. Thank you

like image 504
Joffrey Hernandez Avatar asked Dec 09 '15 10:12

Joffrey Hernandez


People also ask

How to run multiple instances of Tomcat with single server installation?

Running multiple instances of Tomcat with single server installation Steps to configure multiple instances of Tomcat server Step 1) Install Tomcat Server Step 2) Create 2 new different folders in different locations Step 3) Copy the ‘conf’ folder into instances folder from server folder Step 4) Create instance specific startup.bat and shutdown.bat

How to deploy two Tomcat projects at the same time?

If you are using Ultimate, you can create a "Local Tomcat" run configuration in Project1, and go to the "Deployment" tab and drop in the WAR file for your Project1. Then drop in the WAR file from your other project (call it Project2) as an External Source. You would then have both WARs in one run configuration.

Why can't I run Tomcat on two different Macs?

Double check you have added two different tomcat installations in Settings (Preferences on macOS) | Build, Execution, Deployment | Application Servers | Build, Execution, Deployment | Application Servers and select separate tomcat servers in Run/Debug Configurations. Try re-creating the run configurations.

How do I stop Tomcat from running on another server?

Just be sure to edit your conf\server.xml file so that the shutdown ports and HTTP connector ports don’t interfere with other tomcat instances that may be running. e.g. Change the ports where tomcat will be running/debugging.


1 Answers

You problem is that you are trying to start Tomcat with such configuration from within Eclipse IDE.

Ghayel is right that the following is the main reason:

 Caused by: java.lang.IllegalArgumentException: The main resource set specified [C:\DEV\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps\REST] is not valid
 at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:723)
 at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:684)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

See Eclipse IDE in Tomcat FAQ and Eclipse WebTools Project Tomcat FAQ at Eclipse for references.

You problem is caused by combination of the following two facts:

  1. By default Eclipse IDE does not use the server.xml file that you are editing in your IDE, but it processes it when copying into different 'CATALINA_BASE' directory. From your log message that directory is C:\DEV\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps.

    First, look at conf/server.xml file in that directory. It may be different from the file that you edited.

    Second, I would expect that Eclipse IDE processing of server.xml does not support multiple Engine elements. (It may support them, but I will be surprised if it does so).

  2. When Context element is defined in server.xml, failure to start this context results in a startup failure of Tomcat as a whole.

    This is one of the reasons not to define Context elements in server.xml.

AFAIK, a Tomcat server in Eclipse can be configured to use a different CATALINA_BASE directory, and it can be configured to publish contexts as xml files (instead of putting them into server.xml), but I still doubt that such configuration supports multiple Engine elements.

I think your best bet is to configure a Tomcat instance outside of Eclipse and use other tools (such as Apache Ant) to pack and deploy your web application there (either by copying the files + relying on autodeploy, or by using Tomcat Ant tasks to deploy an application onto a running Tomcat instance).

If you do not need for these web services to be on the same JVM, just configure several Server instances in Eclipse and start them in parallel. (Of course, their port numbers must be different).

like image 114
Konstantin Kolinko Avatar answered Oct 13 '22 05:10

Konstantin Kolinko