2014-03-05 87 views
3

我試圖讓簡單的web應用程序運行。我會讓源頭自言自語。數據源使用的Jetty-maven插件配置

的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. 

如何解決這個問題?我不明白爲什麼它沒有看到那個班?

回答

2

也加上c3p0:c3p0:0.9.1.2依賴關係作爲jetty-maven-plugin的依賴關係。我認爲應該這樣做。我認爲你需要它,因爲是的 - 你的WAR文件中有一個依賴關係,但另一方面,爲了能夠設置數據源,Jetty服務器也需要它。 (基本上,在將實際的Web應用程序部署到Jetty之前,您需要它,而當前的設置不會發生這種情況)。