代码改变世界

IntelliJ IDEA 如何引入本地 jar 包

2020-08-12 21:24  猎手家园  阅读(46855)  评论(1编辑  收藏  举报

通过添加Libraries的方式引入:

1、首先在根目录下创建一个 libs 的目录

2、打开 File -> Project Structure

 

3、单击 Libraries  -> "+" -> "Java" -> 选择我们导入的项目主目录,点击OK

 

4、注意:在弹出的方框中点击“Cancel”,取消将其添加到Module中。

 

5、libs目录创建成功,删除目录中添加进来的多余内容,重新添加需要的jar包

 

6、重新添加需要的jar包

 

7、引入jar包:Modules -> 项目 -> “Dependencies”,点击“+” -> “Library”,将刚才创建成功的Library目录加入

 

8、jar包导入成功!

 

9、如果要将引入的jar包打包到war中,需要在pom文件中添加以下配置+

<!-- 引用本地jar包 -->
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>16.8.0</version>
    <scope>system</scope>
    <systemPath>${pom.basedir}/libs/aspose-words-16.8.0-jdk16.jar</systemPath>
</dependency>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells</artifactId>
    <version>8.5.2</version>
    <scope>system</scope>
    <systemPath>${pom.basedir}/libs/aspose-cells-8.5.2.jar</systemPath>
</dependency>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>15.9.0</version>
    <scope>system</scope>
    <systemPath>${pom.basedir}/libs/aspose.slides-15.9.0.jar</systemPath>
</dependency>

 

<!-- 将本地jar包打到war中 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>compile</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                <includeScope>system</includeScope>
            </configuration>
        </execution>
    </executions>
</plugin>