Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running web app in both Jetty and Tomcat

I have a web app which in production I run on Tomcat. It uses the MySQL connector, however it is not bundled up with the war, rather it is included under Tomcat's common lib directory, so that I can access the data source through JNDI.

I would like to do something similar with Jetty (while developing), and more precisely Jetty + Maven. Is there a way for me to include the mysql-connector jar in the classpath when running Jetty through Maven (i.e. not have it bundled in the war file)?

Also I should note that I am using Maven for my build process and have the mysql-connector specified as "provided" scope.

like image 459
Imran Avatar asked Jan 27 '11 07:01

Imran


People also ask

Is Jetty better than Tomcat?

There is no real difference in complexity compared to Jetty.

How do I run a WAR file on a Jetty server?

The easiest way to deploy a web application to Jetty server is probably by copying the WAR file into the $JETTY_HOME/webapps directory. Jetty will scan its $JETTY_HOME/webapps directory at startup for web applications to deploy. Our new app will be deployed at /jetty-app context.

Is Jetty an application server?

Jetty is another application server (this one developed by Eclipse Foundation) that isn't technically a fully featured Java EE container. Just like Tomcat, it lacks support for many Java EE features. And just like Tomcat, you can still use most of the features by including additional third-party dependencies.

Is Undertow better than Tomcat?

Undertow definitely had impressive results in those tests! Compared to Tomcat, it proved to start up faster, handle more load, and also had a far more stable throughput.


1 Answers

Additinally to previous answer: you have to add to your jetty plugin in maven config dependency:

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.version}</version>
            <configuration>
                <stopKey>blah-blah-blah</stopKey>
                <stopPort>9966</stopPort>
                <webAppConfig>
                    <contextPath>/</contextPath>
                </webAppConfig>
                <jettyEnvXml>${basedir}/src/jetty-env.xml</jettyEnvXml>
            </configuration>
            <dependencies>              
                <dependency>
                    <groupId>postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>8.4-701.jdbc4</version>
                </dependency>
            </dependencies>
        </plugin>

And then you can use provided scope at main project dependencies. I did it right now, and it works. Thank you for your question (and Nishant too)

like image 154
javagirl Avatar answered Sep 27 '22 23:09

javagirl