问题
I wanted to download the latest release of Dozer mapper from github, but I didn't find any jar.
There is pom.xml file and I try to compile with command mvn package
. I also added every dependencies to pom.xml file. It created dozer-5.5.0-SNAPSHOT.jar
.
Next I imported this jar to my project, but it throws me java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
.
I also tried to create POM project in the netbeans and build with dependencies. After import to my project, it throws me the same exception.
I don't have any experiences with maven. How can I get correct JAR file?
回答1:
Guess your dozer-package
has a dependency to slf4j
, right?
Then you should checkout this Maven-Plugin: Maven-Assembly-Plugin
This will put your required dependencies into the jar.
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>
If you want always execute the assemby-plugin when you invoke mvn clean package
add this to your maven-assembly-plugin:
<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>
回答2:
You have a correct jar. Simple add commons-beanutils lang and slf4j to you project with dozer or add this libraries as a maven dependencies.
回答3:
Jars required for Dozer dependency.
回答4:
Make the entry in pom.xml file.Make sure the required Jars are present.
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.3.1</version>
</dependency>
<properties>
<osgi.version>4.3.0</osgi.version>
来源:https://stackoverflow.com/questions/14010927/dozer-with-maven