对于Maven项目,我有以下(简称)pom.xml
。我添加了com.google.collections
依赖项,但是当我执行/target/classes
时,我在maven clean package
目录中看不到任何针对此依赖项的类。此外,当我执行JAR时,出现错误(java.lang.NoClassDefFoundError: com/google/common/collect/Iterables
)。我忘记做什么了?
<project>
<groupId>edu.berkeley</groupId>
<artifactId>java-page-rank</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>
<name>PageRank</name>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.0</version>
</dependency>
<!-- http://mvnrepository.com/artifact/com.google.collections/google-collections -->
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:2)
您不会在target/classes
中看到依赖项,这些依赖项仅用于编译并从$HOME/.m2/repository
中获取。
如果您需要运行生成的jar,您需要:
$HOME/.m2/repository
中使用的jar。E.g。对于assembly plugin,您需要将插件添加到插件部分:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>package.for.the.start.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
然后用assembly:single
执行maven,例如:
mvn clean package assembly:single
生成的jar将是target/java-page-rank-1.0-SNAPSHOT-jar-with-dependencies.jar
。
答案 1 :(得分:1)
如果您希望jar包含所有依赖项,请使用test_data
代替test_data = DataFrame({'Qu1': ['other', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'other'],
'Qu2': ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'],
'Qu3': ['other', 'potato', 'other', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'other']})
maven-assembly-plugin