Eclipse/Spring Tool Suite配置Maven

默认情况下使用Eclipse或者Spring Tool Suite创建maven-archetype-webapp项目后,会发现如下几个问题:

  • jdk版本为1.5。
  • web.xml版本为2.3。
  • pom.xml里面的junit为3.1.8版本。
  • 无Web运行环境。

下面针对这几个问题逐一说明解决办法。

 

一、解决jdk版本问题

此问题比较容易解决,将 maven 安装目录下的 conf 文件夹下settings.xml文件复制到 C:\Users\{当前用户名}\.m2\ 目录下。然后找到profiles配置项,在里面添加以下profile配置即可(以下是将jdk设置成1.8版本)。

<profile>
    <id>jdk-1.8</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

 

二、解决web.xml版本问题(此步骤与步骤三同时修改

1、进入 C:\Users\{当前用户名}\.m2\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0\ 路径,复制 maven-archetype-webapp-1.0.jar 文件到别处,然后将其解压出来。

2、找到解压出来的文件里面的 archetype-resources\src\main\webapp\WEB-INF\ 路径下的web.xml文件,使用文本编辑器打开,对其进行编辑然后保存。下面是一个编辑好的web.xml内容(版本修改到4.0的版本)。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    id="WebApp_ID" version="4.0">
    <display-name>Archetype Created Web Application</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

 

三、解决pom.xml中的junit版本问题

与修改web.xml类似,用文本编辑器打开解压出来的文件里面的 archetype-resources\pom.xml 文件进行编辑,然后保存。下面是编辑后的内容(将junit的版本修改为当前最新版本4.12)。

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>${groupId}</groupId>
    <artifactId>${artifactId}</artifactId>
    <packaging>war</packaging>
    <version>${version}</version>
    <name>${artifactId} Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${artifactId}</finalName>
    </build>
</project>

 修改完成后,重新将文件打包成 maven-archetype-webapp-1.0.jar 文件,替换掉 C:\Users\{当前用户名}\.m2\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0\ 目录下原来的 maven-archetype-webapp-1.0.jar 即可。

 

四、解决无web运行环境的问题。

1、右键点击创建的项目,选择 Build Path-->Configure build path… 打开配置窗口,在窗口邮编选择“Libraries”选项卡,然后点击 “Add Libarary…” 按钮。

2、选择“Server Runtime”,然后点击 “Next”按钮。

3、选择已配置好的服务器软件/容器,然后依次保存即可。

 

转载于:https://www.cnblogs.com/QingXiaxu/p/10178142.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值