简单的一个war打包到tomcat下的方法
由于我用的是eclipse安装插件tomcat来发布web应用,而不是用的myeclipse(因为这东西实在庞大了,如果我有需要的插件,我可以直接下载相应的插件,然后丢在eclipse里就对了);
我用的tomcat组件名tomcatPluginV321.zip
我也传在附件里,如果要加在eclipse里用,只需将这个压缩包解压后com.sysdeo.eclipse.tomcat_3.2.1这个文件夹拷到eclipse的plugins目录下,如:
D:\eclipse\eclipse-SDK-3.6.1-win32\eclipse\plugins
对于eclipse里的xml文件编辑器,我也下了一个xmlbuddy_2.0.9.zip,方法使用同上;
然后启动eclipse,然后在window菜单下的perferences选项里就会出现tomcat的一个配置项,如附件tomcat1.jpg文件;
只需配置好你的tomcat文件目录就对啦。
然后你就建一个web project或者建一个普通的java project,但要配置一个web project的目录;
如下就是我所用目录
每个文件的代码我都贴出来:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
index.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
This is my JSP page. <br>
</body>
</html>
hellojstl.jsp:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ taglib prefix = "c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>test your first used JSTL page</title>
</head>
<body>
<c:out value="welcome test your first JSTL page"/><br>
you used the brower is: <br>
<c:out value="${header['User-Agent']}"/>
<c:set var="a" value="David O'Davies"/>
<c:out value="David O'Davies" escapeXml="true"/>
</body>
</html>
build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name = "JustTest" default = "deploy" basedir = ".">
<target name = "init">
<property environment = "env"/>
<property name = "src" value = "${basedir}/src" />
<property name = "webdir" value = "${basedir}/WebRoot" />
<property name = "classes" value = "${webdir}/WEB-INF/classes" />
<property name = "warpath" value = "D:\apache-tomcat-6.0.29\webapps" />
<property name = "" value = "" />
<mkdir dir = "${classes}" />
</target>
<target name = "compile" depends = "init">
<javac srcdir = "${src}" destdir ="${classes}">
</javac>
</target>
<target name = "deploy" depends = "compile">
<war warfile = "${warpath}/JustTest.war" webxml = "${webdir}/WEB-INF/web.xml" >
<fileset dir = "${basedir}/WebRoot" />
</war>
</target>
</project>
warpath指的是tomcat的web项目存放地;
war该命令是指打包命令,warfile指定存放目录及文件名;
备注:由于我正在学JSTL的东西,所以在上面测试中写了一个hellojstl.jsp的文件,这个文件需要将jstl-1.2.jar包一定要放在tomcat的lib目录中。