简体   繁体   English

IntelliJ 添加外部 jar 作为相对路径的依赖项

[英]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.

相关问题 IntelliJ外部jar的相对路径 - IntelliJ external jar relative path Maven:通过相对路径添加对jar的依赖 - Maven: add a dependency to a jar by relative path 如何使用 IntelliJ 中的相对路径从外部库中引用 jar 文件? - How do I reference a jar file from an External Library using relative path in IntelliJ? Maven:通过项目目录外的相对路径向jar添加依赖项 - Maven: add a dependency to a jar by relative path outside the project directory 用本地intellij项目替换外部jar依赖 - Replace external jar dependency with local intellij project 将外部jar添加到我们的依赖项 - add external jar to our dependency 有没有办法从 jar 的 jar 获取相对路径? - Is there a way to get the relative path from a jar of a jar? 使用相对路径将 jar 文件添加到 Eclipse 项目 - Add jar file to Eclipse project with relative path 对于外部jar,如果jar已存在/已复制到lib文件夹,是否有必要在pom.xml文件中添加具有系统路径的依赖项 - For an external jar, is it necessary to add a dependency in pom.xml file with a system path if jar already present/copied to lib folder Spring MVC-无法访问JAR依赖项所需的相对路径中的文件 - Spring MVC - unable to access a file at a relative path required by JAR dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM