2015-01-21 38 views
1

我用maven像行家例外:

<plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>chinahighway.InitHighWay</mainClass> 
          -->入口類名 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 

所有工作的權利。 但我想補充一些地方罐子類路徑,所以我修改像

<plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>chinahighway.InitHighWay</mainClass> 
          -->入口類名 
         </manifest> 
         <manifestEntries> 
          <Class-Path>D:\chinahighway\beyondbjdbc\iijdbc</Class-Path> 
          <Class-Path>D:\chinahighway\beyondbjdbc\hibernate-beyondb</Class-Path> 
         </manifestEntries> 
        </archive> 
       </configuration> 
      </plugin> 

mvn clean install -DskipTests

Java的罐子....

Exception in thread "main" java.lang.NoClassDefFoundError: chinahighway/InitHighWay

如何解決它,並能將jar添加到類路徑中? PLZ幫助我,非常感謝。

回答

0

如果jar不是groupId-artifactId-version.jar 你應該添加

<dependency> 
     <groupId>beyondb</groupId> 
     <artifactId>iijdbc</artifactId> 
     <version>1</version> 
     <scope>system</scope> 
     <systemPath>D:\chinahighway\beyondbjdbc\iijdbc.jar</systemPath> 
    </dependency> 
    <dependency> 
     <groupId>beyondb</groupId> 
     <artifactId>hibernate</artifactId> 
     <version>1</version> 
     <scope>system</scope> 
     <systemPath>D:\chinahighway\beyondbjdbc\hibernate-beyondb.jar</systemPath> 
    </dependency> 

這將產生hibernate-1.jariijdbc-1.jar, 個創建以下目錄

created directories

和刪除添加,添加

<repositories> 
      <!--other repositories if any --> 
      <repository> 
       <id>project.local</id> 
       <name>project</name> 
       <url>file:D:\wyr\chinahighway\highway\src\main\resources\rep</url> 
      </repository> 
     </repositories> 
<dependencies> 
      <dependency> 
       <groupId>beyondb</groupId> 
       <artifactId>iijdbc</artifactId> 
       <version>1</version> 
      </dependency> 
      <dependency> 
       <groupId>beyondb</groupId> 
       <artifactId>hibernate</artifactId> 
       <version>1</version> 
      </dependency> 
<dependencies> 

這將解決你的問題。
Reference

0

嘗試增加

<dependency> 
    <groupId>com.ingres.jdbc</groupId> 
    <artifactId>iijdbc</artifactId> 
    <version>9.2-3.4.10</version> 
    <scope>system</scope> 
    <systemPath>${project.basedir}/lib/iijdbc.jar</systemPath> 
</dependency> 
+0

感謝,但它提示異常在線程「主」 org.springframework.beans.factory.BeanCreationExcepti 上:錯誤創建具有名稱「的entityManagerFactory」類路徑R定義 esource豆[CONF/beyondbjpa.xml ]:調用init方法失敗;嵌套的exceptio n是org.hibernate.boot.registry.selector.spi.StrategySelectionException:無法將 解析爲名稱[org.hibernate.dialect.Beyondb2Dialect]作爲策略 – 2015-01-22 08:28:14

0
<plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>chinahighway.InitHighWay</mainClass> 
          -->入口類名 
         </manifest> 
         <manifestEntries> 
          <Class-Path>lib/iijdbc.jar</Class-Path> 
          <Class-Path>lib/hibernate-beyondb.jar</Class-Path> 
         </manifestEntries> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>copy</id> 
         <phase>install</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>target/lib</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

enter image description here