Skip to content

Instantly share code, notes, and snippets.

@leonelag
Created October 4, 2012 11:23
Show Gist options
  • Save leonelag/3833036 to your computer and use it in GitHub Desktop.
Save leonelag/3833036 to your computer and use it in GitHub Desktop.
How to add dependencies to a project run with jetty-maven-plugin
<!--
Example of data source configuration for Jetty 8
-->
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/myapp</Set>
<New id="MyDataSource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/backendDS</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<!-- Driver for Oracle 9i -->
<!--
<Set name="driverClassName">oracle.jdbc.driver.OracleDriver</Set>
-->
<!-- Driver for Oracle 10g and 11g -->
<Set name="driverClassName">oracle.jdbc.OracleDriver</Set>
<Set name="url">jdbc:oracle:thin:@localhost:1521:XE</Set>
<Set name="username">myuser</Set>
<Set name="password">myuser</Set>
</New>
</Arg>
</New>
</Configure>
<!--
Problem: your application needs a data source (let's say Oracle); you want to
run it with jetty-maven-plugin by using 'mvn jetty:run'. Thus, you need the
Jetty server to start with the database driver in its class path, but you do
not want to add it as a dependency, because you do not want it added to the
final packaged artifact.
The solution is to add the dependency to the plugin itself, as shown below.
-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.7.v20120910</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/myapp</contextPath>
</webApp>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>11.2.0.3</version>
</dependency>
</dependencies>
</plugin>
@chenrui333
Copy link

How did your jetty-env.xml get injected into the plugin in POM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment