jdk+tomcat+myeclipse+spring开发环境配置小记

JDK环境变量配置:

         至 http://www.oracle.com/ 下载jdk

(dos下 “set 环境变量名”可以查看环境变量值,“set 环境变量名=D:\XX”可以修改环境变量)

         新建环境变量JAVA_HOME值为jdk的安装目录,例:D:\jdk1.7.0

         编辑系统变量path,添加:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

       新建环境变量CLASSPATH:.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

       测试:dos下   java –version显示jdk版本信息


Tomcat配置:

       http://tomcat.apache.org/下载tomcat文件(压缩包或安装包)

       正确配置jdk

       新建环境变量:CATALINA_HOME值为tomcat所在目录,例:D:\Tomcat8

(Dos 下运行startup.bat,可以查看错误信息)


Spring配置

 至spring下载地址

下载spring-framework-3.2.0.RELEASE-dist.zip类似文件,使用spring还需必备包commons-logging.jar,将 此文件夹下的commons-logging.jar文件至spring目录下的lib文件夹内。commons-logging.jar 可至 commons-logging.jar下载


Myeclipse添加tomcat及spring支持

1、 Tomcat

window->perferences->myeclipse->servers->tomcat选择对应版本,选中enable,在tomcat home directory中选择tomcat安装的根目录(或者解压路径),其余2个将自动选择

2、  Spring

Javaproject->BuldPath->configure Buld Path->Librares标签->Add Externaljars…,选择spring的lib目录下的所有以RELEASE.jar结尾的jar核心文件文件,包括commons-logging.jar


测试:

1、测试环境配置是否成功:

在myeclipse中新建javaproject名为HelloWordd

在src下新建包名为com.inter->在com.inter包下新建HolleMessage类:

package com.inter;

public interface HelloMessage {  
    void message();//定义抽象的message方法
}  

在src下新建包名为com.bean->在com.bean包下新建HolleBeauty类:

package com.bean;

import com.inter.HelloMessage;  
  
public class HelloBeauty  implements HelloMessage{  
  
    @Override  
    public void message() {  
        // TODO Auto-generated method stub  
        System.out.println("HelloBeautifulWord");  
    } 
}  


在src下新建包名为com.test->在com.test包下新建test类:

package com.test;  
  
import org.springframework.context.ApplicationContext;  
import org.springframework.context.support.FileSystemXmlApplicationContext;  
import com.bean.HelloBeauty;
  
public class test {  
    public static void main(String[] args){
        ApplicationContext ac=new FileSystemXmlApplicationContext("src/applicationContext.xml");//利用文件系统查询applicationContext.xml配置文件  
        HelloBeauty b = (HelloBeauty) ac.getBean("beauty");
        b.message();
    }
}


在src下新建xml配置文件名为applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<beans  
    xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

 	<bean id="beauty" class="com.bean.HelloBeauty"></bean>
 	
</beans>

运行显示:HelloBeautifulWord 则配置成功

2、myeclipse+tomcat+web测试

新建web project名为HelloWeb

HelloWeb->src下新建包com.index->新建Hello.java:

package com.index;

public class Hello {
	private String message = "Hello World";
	
	/** * @return Returns the message. */
	public String getMessage(){ 
		return message; 
	}
	/** * @param message The message to set. */
	public void setMessage(String message){ 
		this.message = message; 
	}
}

在WebRoot下找到index.jsp,修改:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<jsp:useBean id="hello" class="com.index.Hello" scope="page"></jsp:useBean>
<jsp:setProperty name="hello" property="message" value="hello word"></jsp:setProperty>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <%=hello.getMessage() %><br>
  </body>
</html>

在myeclipse窗口中:

(window->perferences->myeclipse->servers->tomcat选择对应版本,选中enable,在tomcat home directory中选择tomcat安装的根目录(或者解压路径),其余2个将自动选择)

右键web项目->myeclipse->add and remove project deployment选择添加的tomcat服务器,点击add。

Myeclipse界面正下方选择servers标签页,选择服务器右键->Run server

服务器启动成功后,默认配置下,至网页访问:localhost:8080 可以看见tomcat版本信息,访问 localhost:8080/HelloWeb/ 页面显示 :Hello Word  则配置成功

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值