IntelliJ:如何将文件夹中的所有jar文件添加到classpath [英] IntelliJ: How to add all jar files in a folder to classpath

查看:228
本文介绍了IntelliJ:如何将文件夹中的所有jar文件添加到classpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用pom.xml文件打开了一个Maven项目:

I recently opened a Maven project with the pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

这个pom文件必须安装Spring Framework。它实际上安装在〜/ .m2 / repository / org / springframework /下。
这当然是一个巨大的文件夹,其中包含许多子文件夹中的许多jar文件。我想使用IntelliJ将所有jar文件添加到classpath。我想问一下如何做到这一点。我现在所能做的只是在另一个之后添加一个jar文件。

This pom file had to install Spring Framework. It was actually installed under ~/.m2/repository/org/springframework/. This is, of course, a huge folder that includes many jar files in many sub-folders. I want to add all jar files to classpath using IntelliJ. I want to ask how to do it. All I can do now is just adding one jar file after the other.

推荐答案

1。)文件夹可以作为类路径添加到构建中,但是该目录应该包含类。有关更多详细信息,请参阅此处 - 在类路径intelliji中添加目录

1.) Folders can be added as class path in build, However the directory is expected to contain classes. Refer here for more details - Add directory in class path intelliji

2。)关于来自本地Maven存储库的jar,只能通过打开Maven项目来实现Intelliji使用(Alt + F + O)

2.) With respect to jars from local Maven repository, It can be achieved only by opening the Maven project in Intelliji using (Alt + F + O)


(Alt + F + O)并指定pom.xml的路径(Maven项目)
描述符文件)。 IntelliJ IDEA基于Maven
项目描述符文件创建项目

(Alt + F + O) and specify the path to pom.xml (the Maven project descriptor file). IntelliJ IDEA creates a project based on the Maven Project descriptor file

确保您在Intelliji中配置Maven设置

Ensure you congigure Maven settings in Intelliji at

File -> Settings -> Build, Execution, Deployment -> Maven

在此处提供相同的本地存储库路径和maven设置文件。

Give the same local repository path and maven settings file here.

发布哪个,做一个mvn clean install -o。
这个版本将从已经可用的本地存储库中获取jar。但是,它可能会首次尝试下载pom文件 - 确保Internet已连接。

Post which, do a mvn clean install -o . This build will pick up jars from local repository, which is already available. However, it may try and download pom files for the first time - ensure Internet is connected.

3。)或者,您可以在本地maven中查找* .jar存储库路径 - 将粘贴复制到某个位置,并将Intelliji中的这些jar作为库。

3.) Alternatively, You can do a find *.jar inside local maven repository path - Copy paste to an location and refer those jars in Intelliji as libraries.

这篇关于IntelliJ:如何将文件夹中的所有jar文件添加到classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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