将外部库.jar添加到Spring启动.jar / lib而不安装mvn

时间:2017-04-26 18:14:48

标签: java spring maven spring-boot

我一直在这个网站上和其他人一起阅读,试图弄清楚如何在不进行mvn安装的情况下添加这些外部罐子,并且没有取得任何成功。我正在读某个地方,那个maven-shade可以解决我的问题,但我永远无法让它工作?我知道spring boot不喜欢系统范围但是如果我选择别的东西似乎会出错?

<?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>org.springframework</groupId>
    <artifactId>gs-rest-service</artifactId>
    <version>0.1.0</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
       ...
        <dependency>
              <groupId>sample</groupId>  
               <artifactId>com.sample</artifactId>  
               <version>1.0</version> 
              <scope>system</scope>
              <systemPath>${project.basedir}/src/main/resources/lib/enterprise.jar</systemPath>
        </dependency>
        <dependency>
              <groupId>sample1</groupId>  
               <artifactId>com.sample1</artifactId>  
               <version>1.0</version> 
              <scope>system</scope>
              <systemPath>${project.basedir}/src/main/resources/lib/gs.jar</systemPath>
        </dependency>
        <dependency>
              <groupId>sample2</groupId>  
               <artifactId>com.sample2</artifactId>  
               <version>1.0</version> 
              <scope>system</scope>
              <systemPath>${project.basedir}/src/main/resources/lib/Util.jar</systemPath>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>



    </dependencies>

    <properties>
        <java.version>1.8</java.version>
        <start-class>ves.sfdc.Application</start-class>
    </properties>


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

        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>



</project>

1 个答案:

答案 0 :(得分:1)

您可以创建一个新目录&#34; lib&#34;在你的项目中,将你的jar放在这个目录中,然后将它们添加到你的类路径中。

如果您的IDE是IntelliJ,您可以点击此链接:

Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project

如果您使用其他IDE,则必须在Google上找到如何在项目类路径中添加jar。