[英]IntelliJ add external jar as dependency from relative path
Reviving this question: IntelliJ external jar relative path because the answers were not very helpful to me.恢复这个问题: IntelliJ external jar relative path因为答案对我没有太大帮助。
I'm just trying out IntelliJ IDE and I want to add an external jar to my java project.
我只是在试用 IntelliJ IDE,我想在我的 java 项目中添加一个外部 jar。
I have already figured out how to add external jars to my project in ProjectSettings -> Modules -> Dependencies.
我已经弄清楚了如何在 ProjectSettings -> Modules -> Dependencies 中将外部 jar 添加到我的项目中。 But the path is always absolute.
但路径总是绝对的。 I haven't found a way to make the path relative to the project folder (my lib folder is inside my project folder).
我还没有找到一种方法来使路径相对于项目文件夹(我的 lib 文件夹在我的项目文件夹中)。
eg I don't want this C:\Users\AUser\IdeaProjects\AProject\lib\alibrary.jar
例如我不想要这个 C:\Users\AUser\IdeaProjects\AProject\lib\alibrary.jar
Instead I want this.
相反,我想要这个。 ...\AProject\lib\alibrary.jar
...\AProject\lib\library.jar
In Netbeans this was possible by just checking a checkbox.
在 Netbeans 中,这可以通过选中一个复选框来实现。 Is there something similar in IntelliJ?
IntelliJ 中有类似的东西吗?
If not, how do you deal with the situation when someone else is trying to open up your project?
如果没有,当其他人试图打开您的项目时,您如何处理这种情况? Does he need to edit all library paths?
他需要编辑所有库路径吗?
What I want is to be able to add dependencies from a relative path so that my, uh, "Microservice" I guess, will work in tandem with the rest of the project when moved to a different computer, or CI and such.我想要的是能够从相对路径添加依赖项,以便我的,呃,我猜的“微服务”,当移动到另一台计算机或 CI 等时,将与项目的其余部分协同工作。 No absolute paths whatsoever.
没有绝对路径。
The responses in the question mention the variable $MODULE_DIR
.问题中的回答提到了变量
$MODULE_DIR
。 I've found https://www.jetbrains.com/help/idea/absolute-path-variables.html which has mention of a variable $MODULE_IML_DIR
.我发现https://www.jetbrains.com/help/idea/absolute-path-variables.html提到了一个变量
$MODULE_IML_DIR
。 Neither worked for me.都不适合我。
$MODULE_DIR will be the directory of the IntelliJ Module - so probably try $MODULE_DIR/../../AProject/lib/alibrary.jar (or what your relative path will be)
$MODULE_DIR 将是 IntelliJ 模块的目录 - 所以可能尝试 $MODULE_DIR/../../AProject/lib/alibrary.jar (或者你的相对路径是什么)
If the library is inside the project root, the path will be stored relatively using the placeholder.如果库位于项目根目录中,则路径将使用占位符相对存储。
In the library .xml
file or in the project .iml
file you'll see something like this:在库
.xml
文件或项目.iml
文件中,您会看到如下内容:
<component name="libraryTable">
<library name="log4j-1.2.17">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/log4j-1.2.17.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.