Adding external library to artifact jar in IntelliJ IDEA

后端 未结 2 1537
孤街浪徒
孤街浪徒 2020-11-22 03:11

How can I add an external library to a project in IntelliJ IDEA so that when I build an artifact it still has access to the classes in the library?

I have created a

相关标签:
2条回答
  • 2020-11-22 03:19

    If you are using maven to build your application then this is not the correct way to add external library. You should either

    1. Do an install of your library like below mvn install:install-file -Dfile=myJar.jar -DgroupId=com.yourproject -DartifactId=yourproject -Dversion={version} -Dpackaging=jar.
    2. Use system path like explained here.

    Option 1 is prefered since you don't have to keep jar in your project.

    0 讨论(0)
  • 2020-11-22 03:27

    You have 2 options here:

    • extract the dependency into the artifact jar so that the app is the single executable jar with all the dependencies
    • link the dependent jars via the Manifest.MF and copy them near the application main jar

    I've prepared a sample project that demonstrates both approaches: HelloWithDependencies.zip.

    The artifacts are produced into out\single and out\linked directories.

    Relevant configurations:

    0 讨论(0)
提交回复
热议问题