2012-12-23 34 views
0

我想從github上下載最新版本的Dozer mapper,但是我沒有找到任何jar。推土機與maven

有pom.xml文件,我嘗試編譯命令mvn package。我還將每個依賴項添加到pom.xml文件中。它創建了dozer-5.5.0-SNAPSHOT.jar

接下來我將這個jar導入到了我的項目中,但它會拋出我java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

我也嘗試在netbeans中創建POM項目並使用依賴關係進行構建。導入到我的項目後,它引發了同樣的異常。

我對maven沒有任何經驗。我怎樣才能得到正確的JAR文件?

回答

1

猜你的dozer-package有一個依賴slf4j,對吧?

那麼你應該結帳這個Maven的插件:Maven-Assembly-Plugin

這將會把你需要的依賴放進瓶子裏。

Here you can read, how to use it

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    version>2.4</version> 
    <configuration> 
     <descriptorRefs> 
     <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     <archive> 
     <manifest> 
     <mainClass>your.main.class</mainClass> 
     </manifest> 
     </archive> 
    </configuration> 
    <executions> 
     <execution> 
     <phase>package</phase> 
     <goals> 
     <goal>single</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 
</plugins> 

如果當你調用mvn clean package 添加到您的Maven的組裝插件希望總是執行assemby-插件:

<executions> 
     <execution> 
     <id>make-assembly</id> <!-- this is used for inheritance merges --> 
     <phase>package</phase> <!-- bind to the packaging phase --> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     </execution> 
</executions> 
+0

是的,這已經得到了依賴於公地的BeanUtils,org.apache.commons,org.slf4j。你能告訴我如何正確檢索mainClass的值嗎? – misco

+0

這是帶有限定名稱的主要班級。我將該網站鏈接到可以閱讀的地方,以及如何使用它。還做了我的答案更新。 pom.xml文件中的 – Timo

+0

包含此插件,但沒有配置和執行。這裏是鏈接https://github.com/DozerMapper/dozer/blob/master/pom.xml – misco

0

你有一個正確的罐子。簡單的添加commons-beanutils lang和slf4j給你用推土機項目或者將這些庫添加爲maven依賴項。

-1

在pom.xml文件中創建條目。確保所需的Jars存在。需要推土機依賴

<dependency> 
     <groupId>net.sf.dozer</groupId> 
     <artifactId>dozer</artifactId> 
     <version>5.3.1</version> 
    </dependency> 
     <properties> 
<osgi.version>4.3.0</osgi.version> 

+0

他已經添加了jar。這是缺少的依賴關係。尤其是發生異常的普通罐子 – dirai