I'm trying to get simple web-app running. I'll let the source speak for itself.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>WelcomeSite</groupId>
<artifactId>WelcomeSite</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.2.v20140210</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<contextPath>/</contextPath>
<stopKey>STOP</stopKey>
<stopPort>8005</stopPort>
<jettyXml>src/main/webapp/WEB-INF/jetty-env.xml</jettyXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.1.0.RC2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.174</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.7.SP1</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
</dependencies>
</project>
jetty-env.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id ="h2db" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="h2Datasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/h2db</Arg>
<Arg>
<New class="com.mchange.v2.c3p0.ComboPooledDataSource">
<Set name="driverClass">org.h2.Driver</Set>
<Set name="jdbcUrl">jdbc:h2:~/temp/testdb</Set>
<Set name="username">sa</Set>
<Set name="password"></Set>
</New>
</Arg>
</New>
</Configure>
Executing mvn jetty:run gives me this:
[INFO] --- jetty-maven-plugin:9.1.2.v20140210:run (default-cli) @ WelcomeSite ---
[INFO] Configuring Jetty for project: WelcomeSite
[INFO] webAppSourceDirectory not set. Trying src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = /home/esc/IdeaProjects/WelcomeSite/target/classes
[INFO] Configuring Jetty from xml configuration file = /home/esc/IdeaProjects/WelcomeSite/src/main/webapp/WEB-INF/jetty-env.xml
2014-03-05 12:58:22.762:WARN:oejx.XmlConfiguration:main: Config error at <New id="h2Datasource" class="org.eclipse.jetty.plus.jndi.Resource"><Arg>jdbc/h2db</Arg><Arg>| <New class="com.mchange.v2.c3p0.ComboPooledDataSource"><Set name="driverClass">org.h2.Driver</Set><Set name="jdbcUrl">jdbc:h2:~/temp/testdb</Set><Set name="username">sa</Set><Set name="password"/></New>| </Arg></New> java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource in file:/home/esc/IdeaProjects/WelcomeSite/src/main/webapp/WEB-INF/jetty-env.xml
[INFO] Jetty server exiting.
How to resolve this? I can't understand why it doesn't see that class?
Add the c3p0:c3p0:0.9.1.2 dependency as dependency of the jetty-maven-plugin as well. I think that should do it. I think you need it, as yeah -- you have as a dependency that will be in your WAR file, but, on the other hand, the Jetty server will also need it in order to be able setup the data source. (Basically, you need it before the actual web application has been deployed to Jetty, which is not what will be happening with your current setup).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With