我正在努力让简单的网络应用运行。我会让消息来源说话。
的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>
码头-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>
执行mvn jetty:run
给了我这个:
[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.
如何解决这个问题?我不明白为什么它没有看到那个班级?
答案 0 :(得分:2)
将c3p0:c3p0:0.9.1.2
依赖项添加为jetty-maven-plugin
的依赖项。我认为应该这样做。我认为你需要它,因为是 - 你作为一个依赖项将在你的WAR文件中,但另一方面,Jetty服务器也需要它,以便能够设置数据源。 (基本上,在将实际的Web应用程序部署到Jetty之前,您需要它,这不是您当前设置所发生的情况)。