And*_*v93 2 java maven apache-spark
我正在通过Maven与Apache Spark一起工作,并且尝试通过包含第3方jar并尝试利用其中的某些方法来修改源。
使用编译Spark项目时出现以下错误
mvn -Dhadoop.version=2.2.0 -Dscala-2.11 -DskipTests clean package
Run Code Online (Sandbox Code Playgroud)
not found: object edu
[ERROR] import edu.xxx.cs.aggr._
Run Code Online (Sandbox Code Playgroud)
我修改ResultTask.scala为包含导入语句。因此,maven无法找到我要使用的jar并将其与项目链接。
我已经将依赖项添加到pom.xml文件中,如下所示:
<dependency>
<groupId>edu.xxx.cs</groupId>
<artifactId>aggr</artifactId>
<version>0.99</version>
<scope>system</scope>
<systemPath>${basedir}/aggr.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我尝试链接的jar文件与spark pom.xml文件位于同一目录中。我将此依赖项添加到pom.xml。我将其插入pom.xml文件中的2个现有依赖关系之间。我不确定出什么问题,但是我现在想立即关联该jar,以便可以使用其中的方法。我也不确定我是否应该使用特定于groupId,artifactId和版本的任何东西。edu.xxx.cs.aggr是包含其他源文件和软件包的根软件包。我将不胜感激任何帮助。
更新
我用了
mvn install:install-file -Dfile=<path-to-file> -DgroupId=edu.xxx.cs -DartifactId=aggr -Dversion=0.99 -Dpackaging=jar to install the jar to the .m2 repo. I checked the repo to see if it was installed, and it was.
Run Code Online (Sandbox Code Playgroud)
我将pom.xml中的依赖项更改为
<dependency>
<groupId>edu.purdue.cs</groupId>
<artifactId>aggr</artifactId>
<version>0.99</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我仍然遇到相同的错误。
这就是我向maven pom.xml添加系统依赖项的方式。在项目根路径中,我创建了lib目录,并在其中放置了jar文件。
<dependency>
<groupId>com.sshx</groupId>
<artifactId>sshx</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sshxcute-1.0.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如果仍然遇到相同的问题,请尝试通过从jar文件位置发出以下命令来手动添加依赖项
mvn install:install-file -Dfile=sshxcute-1.0.jar -DgroupId=com.sshx -DartifactId=sshx -Dversion=1.0 -Dpackaging=jar
Run Code Online (Sandbox Code Playgroud)
此命令会将jar作为依赖项添加到您的.m2存储库,您需要按以下方式更改pom.xml依赖项:
<dependency>
<groupId>com.sshx</groupId>
<artifactId>sshx</artifactId>
<version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
完成后,mvn clean install从命令提示符处发出命令并构建您的应用程序。
但是,另一种选择是创建本地存储库。参见此线程: 如何在Maven项目中包括本地jar文件