maven之jdk升级配置和jar包升级配置

来源:互联网 发布:node.js搭建 编辑:程序博客网 时间:2024/05/16 16:04

一 jar包升级配置

如下面的代码所示,在properties标签中,加入<spring.version>配置,下面<dependency>中的<version>版本配置使用${spring.version}。例如:我们要升级项目中spring版本,我们直接改spring.version标签中的版本号即可。

<properties>

   <!-- jar包统一升级管理 -->

   <spring.version>3.2.2.RELEASE</spring.version>

 </properties>

 <dependencies>

   <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-core</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-beans</artifactId>

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

   </dependency>

   <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-context</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-aop</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-expression</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-web</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-webmvc</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-tx</artifactId>

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

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-jdbc</artifactId>

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

    </dependency>

    <!-- spring end-->

   </dependencies>

 

二  maven jdk升级配置

maven 默认使用的 jdk 版本一般较低。

新建一个 maven项目,如下


项目左下方出现一个感叹号,JRE显示的是 1.5 版本。解决方式有两种,一种是配置 pom.xml,一种是配置 settings.xml

方式一:settings.xml配置

打开 %maven%/conf/settings.xml文件并编辑它(%maven%表示 maven 的根目录) 

<profiles>
  
<profile>
    
<id>development</id>
    
<activation>
      
<jdk>1.7</jdk>
      
<activeByDefault>true</activeByDefault>
    
</activation>
    
<properties>
      
<maven.compiler.source>1.7</maven.compiler.source>
      
<maven.compiler.target>1.7</maven.compiler.target>
      
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
    
</properties>
  
</profile>
</profiles>

找到 <profiles>节点,并添加如上配置(本机 jdk 1.7.0_79版本,配置时修改成你本机的 jdk版本)。保存并关闭。重启 eclipse即可。
重启后配置生效。

方式二:pom.xml配置

<build>节点添加如下配置(本机 jdk 1.7.0_79版本,配置时修改成你本机的 jdk版本):

<build>
  
<plugins>
    
<plugin>
      
<groupId>org.apache.maven.plugins</groupId>
      
<artifactId>maven-compiler-plugin</artifactId>
      
<configuration>
        
<source>1.7</source>
        
<target>1.7</target>
      
</configuration>
    
</plugin>
  
</plugins>
</build>

配置完成后,需要执行一次更新项目配置的动作。选中项目 -->右键 --> Maven --> Update Projecteclipse luna版本,helios
indigo
版本选择 Update Project Configuration)。
pom.xml
仅作用于当前项目(每个项目都需要配一次),而 settings.xml的配置是全局的(仅需要配一次)。以上两种配置方式中选其一即可。