Alex
Alex

Reputation: 163

Tomcat 7 User specific server.xml

I have a Java8/Maven based project, in which I use the tomcat7-maven-plugin:

<plugins>
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <executions>
            <execution>
                <id>tomcat-run</id>
                <goals>
                    <goal>exec-war-only</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                    <path>/</path>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

Finally the result of this project is a fat jar file. Based on this configuration inside of the jar file in directory conf I don't see any server.xml, but my service works. So I believe Tomcat will use some kind of default "server.xml" internally.

I know, it is possible to use a user specific server.xml file. This can be done by adding <serverXml>src/main/tomcatconfiguration/server.xml</serverXml> inside of the <configuration>-tag and add the file itself. This file can then be found inside of the conf-directory of the jar file.

My user specific server.xml file looks like this:

<Server port="8005" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.core.JasperListener" />
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

    <Service name="Catalina">
        <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" />
        <Engine name="Catalina" defaultHost="localhost">
            <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
                <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
            </Host>
        </Engine>
    </Service>
</Server>

The service itself - completely independently from Tomcat - handles connections of standard TCP/IP sockets using methods like sun.nio.ch.ServerSocketAdaptor.bind

In case of adding this user specific server.xml, the reconnection/renewed binding of ports will crash. It seems, that a port - once it open - is not closed correctly, such that a reconnection will throw exception java.net.BindException: Address already in use: bind. It does not crash, if I do not add the user specific server.xml.

Can somebody tell me, if there are mistakes in my server.xml or any circumstances, why ports are not released correctly? It will crash with any port I bind, unbind, and rebind - so there is not conflict with other applications.

Hint: I know, that this plugin is old and it includes a tomcat 7.0.37. Maybe there incompatibilities to this version? Does somebody know, how to overwrite the internal used tomcat version?

Upvotes: 0

Views: 40

Answers (0)

Related Questions