Maven:将文件夹或jar文件添加到当前类路径中 [英] Maven: add a folder or jar file into current classpath

查看:483
本文介绍了Maven:将文件夹或jar文件添加到当前类路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven-compile插件来编译类。现在我想将一个jar文件添加到当前的类路径中。该文件保留在另一个位置(请说c:/jars/abc.jar。我更喜欢将此文件保留在此处)。我怎样才能做到这一点。
如果我在参数中使用classpath:

I am using maven-compile plugin to compile classes. Now i would like to add one jar file into current classpath. that file stays in another location (let says c:/jars/abc.jar . i prefer to leave this file here). How can i do that. If i use classpath in the argument:

<configuration>
 <compilerArguments>
  <classpath>c:/jars/abc.jar</classpath>
 </compilerArguments>
</configuration>

它将无效,因为它将覆盖当前的类路径(包括所有依赖项)

it will not working because it will override the current classpath (that include all the dependencies)

请帮助我。

推荐答案

之前可能会有人问过这个问题。请参阅我可以添加罐子吗? maven 2构建类路径而不安装它们?

This might have been asked before. See Can I add jars to maven 2 build classpath without installing them?

简而言之:将jar包含为系统范围的依赖项。这需要指定jar的绝对路径。

In a nutshell: include your jar as dependency with system scope. This requires specifying the absolute path to the jar.

参见 http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

这篇关于Maven:将文件夹或jar文件添加到当前类路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆