具体分三步进行。由于要修改jar包内容,所以先关闭MyEclipse。
一、创建自定义模板(*.vtl文件)
1.可以在目录
(MyEclipse安装目录)\Common\plugins\com.genuitec.eclipse.j2eedt.core_8.6.1.me201010211225\templates\velocity\welcome
找到Jsp.vtl。注意此路径根据MyEclipse版本不同(我这里是MyEclipse8.6),plugins目录下的"com.genuitec.eclipse.j2eedt.core_8.6.1.me201010211225"这个文件夹名字会有所区别,但"com.genuitec.eclipse.j2eedt.core"应该是相同的。
将Jsp.vtl文件copy一份,我这里命名为tbs_jsp.vtl。
2.或者直接创建一个新文件(tbs_jsp.vtl)
内容为:
#*---------------------------------------------# # Template for a JSP with bootstrap # @version: 1.0 # @author: cyk #---------------------------------------------# *#<%@ page language="java" import="java.util.*" pageEncoding="$encoding"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <title>Bootstrap 101 Template</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="<%=basePath%>/js/bootstrap3.0/css/bootstrap.min.css" rel="stylesheet" media="screen"> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="../../assets/js/html5shiv.js"></script> <script src="../../assets/js/respond.min.js"></script> <![endif]--> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="//code.jquery.com/jquery-2.0.3.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="<%=basePath%>/js/bootstrap3.0/js/bootstrap.min.js"></script> </head> <body> <h1>Hello World!</h1> </body> </html>
可根据自己的需要对内容进行修改。
二、将模板添加到MyEclipse
首先必须找到MyEclipse安装目录下的Commons\plugins文件夹中的"com.genuitec.eclipse.wizards_8.6.0.me201007140905.jar"这个包,同之前一样,这个命名也是根据版本而有所区别,所以可以直接搜索"wizards"找到"com.genuitec.eclipse.wizards_*.jar",打开该压缩包:
1.首先打开templates.xml
根节点templateLibry下的每个template都是一个模板文件的资料。拷贝第一个(name="Default JSP template")并在其后粘贴,修改内容(着色部分):
<template context="com.genuitec.eclipse.wizards.jsp" script="templates/jsp/tbs_jsp.vtl" name="JSP template with bootstrap by cyk"/>
tbs_jsp.vtl就是刚才创建的模板文件名。name在MyEclipse创建新JSP文件时显示。
2.在该压缩包下找到目录templates\jsp
将刚才的新创建的模板文件(tbs_jsp.vtl)粘贴到该目录下,完成这两部后,整个"com.genuitec.eclipse.wizards_*.jar"要重新打包
三、其他
打开MyEclipse,new → Jsp(Advanced Templates)时就可以选择刚才创建的模板。
要修改JSP模板的的pageEncoding,可以直接在模板文件写死,或者在MyEclipse菜单栏 Window → Preferences 打开 "MyEclipse → Files and Editors → JSP" 将Encoding修改为UTF-8或其他。
通过Preferences修改,其他的JSP文件的默认pageEncoding也会修改默认。