Maven Eclipse プラグインで Servlet 3.0 プロジェクト

現時点?の Maven Eclipse プラグイン
 1.2.0.20120906 バージョンの m2e プラグイン
で作成すると J2SE-1.5 で、Servlet バージョン 2.3 になってしまう。

f:id:posturan:20160313225654j:plain



これを、Java1.7 で、Servlet バージョン 3.0 にする。

プラグインが作成する .classpath は、

   <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
      <attributes>
         <attribute name="maven.pomderived" value="true"/>
      </attributes>
   </classpathentry>

→→→これを、JavaSE-1.7 にする

.settings の下も 同様に Maven が作成するので Java 1.5 をターゲットを 1.7 にする

 プラグインから作成された org.eclipse.jdt.core.prefs は、、

 3行目 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
 5行目 org.eclipse.jdt.core.compiler.compliance=1.5
12行目 org.eclipse.jdt.core.compiler.source=1.5

 org.eclipse.wst.common.project.facet.core.xml は、以下のように生成され
Servlet バージョンは、2.3 である。

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="java" version="1.5"/>
  <installed facet="jst.web" version="2.3"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

これを以下のように書き換える。

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="jst.web"/>
  <fixed facet="wst.jsdt.web"/>
  <fixed facet="java"/>
  <installed facet="java" version="1.7"/>

  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

次にデプロイメント記述子の修正、 src/main/webapp/WEB-INF/web.xml

Maven プラグインは以下のように作成してしまう。


<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >


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

以下のように書き換える。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
 xmlns="http://java.sun.com/xml/ns/javaee
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 id="WebApp_ID" version="3.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>

JavaEE パースペクティブで、
一旦、プロジェクトを閉じてから開き直すことで以下のようになる。



なお、Maven プラグインは、src/main/java フォルダを作ってくれないので、自分で作らないといけない。