Eclipse Maven project index.jsp, web.xml file version problem solving

Eclipse Maven project index.jsp, web.xml file version problem solving

 

================================

© Copyright sweet potatoes Yao August 6, 2019

http://fanshuyao.iteye.com/

 

I. Description of the problem

When Eclipse Maven project, created out of the index.jsp page and web.xml file version is not what we want. And jdk version 1.5 or, if to solve these problems, to quickly create a suitable version of it?

 

Second, the solution

1, jdk version 1.5 to solve the problem

Method a: Modify the Maven settings.xml file configuration, Profiles (this is the complex s) increases the node follows:

 

<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>

Version is set according to their own needs modification, the above is JDK1.8 

 

 

Complete configuration is as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:\0soft\repository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
  </servers>
  <mirrors>
	 <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>
  <profiles>
	<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>

  </profiles>
</settings>

 

 

Method Two: Modify pom.xml file when creating maven project, increasing the plugins configuration item

 

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
      <encoding>UTF-8</encoding>
      <file>
        <name>.settings/org.eclipse.core.resources.prefs</name>
        <content>  
          <![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=UTF-8${line.separator}]]>
        </content>
      </file>
    </configuration>
  </plugin>
</plugins>

 Save modified, then the project right, select Maven >> Update Project

 

 

The complete code is as follows:

 

<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>com.lqy</groupId>
  <artifactId>myShiro4</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>myShiro4 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>myShiro4</finalName>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
				<encoding>UTF-8</encoding>
				<file>
					<name>.settings/org.eclipse.core.resources.prefs</name>
					<content>  
	               <![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=UTF-8${line.separator}]]>
					</content>
				</file>
			</configuration>
		</plugin>
	</plugins>
  </build>

</project>

 

 

2、解决index.jsp、web.xml文件版本问题

找到自己配置的Maven仓库下载的位置:

我的是

 

D:\0soft\repository\

 

在该目录下,进入到如下目录:

 

D:\0soft\repository\org\apache\maven\archetypes\maven-archetype-webapp\

 看到有个1.0的文件夹(可能有多个版本,我的只有1.0,和你创建Maven项目时选择的版本对应)

 

进入目录:

 

D:\0soft\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0

 看到有一个Jar文件:

 

 

maven-archetype-webapp-1.0.jar

 

 

需要修改这个文件。注意:修改前请备份,请备份,请备份!

 

将这个Jar文件解压。

进入到archetype-resources目录:

 

D:\0soft\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0\maven-archetype-webapp-1.0\archetype-resources

 首先看到的是一个pom.xml文件,我们可以修改这个文件,默认创建maven项目时就是用这个文件生成的。

 

 

修改成这样:

 

<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>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
				<encoding>UTF-8</encoding>
				<file>
					<name>.settings/org.eclipse.core.resources.prefs</name>
					<content>  
	               <![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=UTF-8${line.separator}]]>
					</content>
				</file>
			</configuration>
		</plugin>
	</plugins>
  </build>

</project>

以后每个项目创建时都是这样,不用修改,也解决了第一个问题jdk版本过低的问题。 

 

 

接着,继续进入到(src\main\webapp)目录

D:\0soft\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0\maven-archetype-webapp-1.0\archetype-resources\src\main\webapp

 

看到有index.jsp文件,修改成:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>标题</title>
</head>
<body>

</body>
</html>

 

进入到WEB-INF目录 

修改web.xml文件:

<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">

<web-app>
	<display-name>Archetype Created Web Application</display-name>
</web-app>

 

最后,退到解压后的目录:

D:\0soft\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0\maven-archetype-webapp-1.0

 将maven-archetype-webapp-1.0目录下的2个文件夹打包成jar包即可,复制到目录

D:\0soft\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0

下即可。 

 

 

 最后的最后,送上修改好的Jar包,解压出Jar包替换就可以。记得,先备份。

下载见附件:maven-archetype-webapp-1.0.zip

 

 

================================

©Copyright 蕃薯耀 2019年8月6日

http://fanshuyao.iteye.com/

 

Guess you like

Origin fanshuyao.iteye.com/blog/2443263