[英]Exception while executing java class
I executed this command 我执行了这个命令
mvn compile exec:java -Dexec.classpathScope=compile -Dexec.mainClass=crawler.Crawler
and found this 并发现了这个
An exception occured while executing the Java class.
执行Java类时发生异常。 org/apache/log4j/Logger
组织/阿帕奇/ log4j的/记录器
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" si:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
<repository>
<id>twitter4j.org</id>
<name>twitter4j.org Repository</name>
<url>http://twitter4j.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
second part 第二部分
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
Error 错误
java.lang.NoClassDefFoundError: org/apache/log4j/Logger
java.lang.NoClassDefFoundError:org / apache / log4j / Logger
You need to add dependency on log4j 您需要添加对log4j的依赖
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
to your pom.xml file (after dependency on junit). 到pom.xml文件(依赖于junit之后)。
You can read about this dependency in maven repo: http://mvnrepository.com/artifact/log4j/log4j/1.2.17 您可以在Maven仓库中了解有关此依赖项的信息: http : //mvnrepository.com/artifact/log4j/log4j/1.2.17
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.