今天部署项目,我打包的jar包和我对接项目居然不能用,原来是对接项目jdk是1.7,其实问题不大,可以同步maven使用jdk7重新进行打包。

1、设置编译版本为jdk 1.8

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<build>

    <plugins>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>

            <version>3.5</version>

            <configuration>

                <source>1.8</source>

                <target>1.8</target>

                <encoding>UTF-8</encoding>

            </configuration>

        </plugin>

    </plugins>

</build>

2、 maven排除依赖jar包中的子jar

1

2

3

4

5

6

7

8

9

10

<dependency>
   

<groupId>com.xx.xx</groupId>
   

<artifactId>xx</artifactId>
   

<version>${xx.version}</version>
   

<exclusions>
       

<exclusion>
           

<groupId>org.springframework</groupId>
          

 <artifactId>*</artifactId>
       

</exclusion>
<br></exclusions>

</dependency>

   
3、将maven将java项目依赖包一起打入一个jar包内需要的配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<plugin>   

           <artifactId>maven-assembly-plugin</artifactId>   

                <configuration>   

                    <descriptorRefs>   

                        <descriptorRef>jar-with-dependencies</descriptorRef>   

                    </descriptorRefs>   

                    <archive>   

                        <manifest>   

                          <mainClass></mainClass>   

                        </manifest>   

                    </archive>   

                </configuration>   

                <executions>   

                    <execution>   

                        <id>make-assembly</id>   

                        <phase>package</phase>   

                        <goals>   

                            <goal>single</goal>   

                        </goals>   

                    </execution>   

             </executions>   

</plugin>

打包的命令: 在项目的目录下的命令行输入:mvn clean package

或者使用idea打包插件重新打包即可