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

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

问题描述

我正在使用 maven-compile 插件来编译类.现在我想在当前类路径中添加一个 jar 文件.该文件保留在另一个位置(假设是 c:/jars/abc.jar .我更愿意将这个文件留在这里).我该怎么做?

如果我在参数中使用类路径:

<预><代码><配置><编译器参数><classpath>c:/jars/abc.jar</classpath></compilerArguments></配置>

它不会工作,因为它将覆盖当前的类路径(包括所有依赖项)

解决方案

这可能以前有人问过.参见 我可以添加 jars 到maven 2 构建类路径而不安装它们?

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

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

I am using maven-compile plugin to compile classes. Now I would like to add one jar file into the current classpath. That file stays in another location (let's say 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 work because it will override the current classpath (that includes all the dependencies)

解决方案

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

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

See also http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

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

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