Oops! JMF Quick Start
Purpose:
學(xué)習(xí)完后能夠?qū)W會(huì)操作JMF.
JMF是java media framework,能夠控制流媒體
Reference :
http://blog.csdn.net/oscar999/archive/2006/12/11/1438694.aspx
Precondition:
Eclipse 3.3 europa
jmf-2_1_1e-windows-i586.exe
/Files/pixysoft/jmf-2_1_1e-windows-i586.part1.rar
/Files/pixysoft/jmf-2_1_1e-windows-i586.part2.rar
/Files/pixysoft/jmf-2_1_1e-windows-i586.part3.rar
/Files/pixysoft/jmf-2_1_1e-windows-i586.part4.rar
Quick Start:
新建一個(gè)java project,項(xiàng)目名為Oops_JMF

在項(xiàng)目里面添加一個(gè)lib目錄,并添加以下jar文件,全部可以在jmf-2_1_1e-windows-i586.exe里面找到

在src目錄下面添加以下文件:
SimpleAudioPlayer.java
import javax.media.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
public class SimpleAudioPlayer
{
private Player audioPlayer = null;
public SimpleAudioPlayer(URL url) throws IOException, NoPlayerException,
CannotRealizeException
{
audioPlayer = Manager.createRealizedPlayer(url);
}
public SimpleAudioPlayer(File file) throws IOException, NoPlayerException,
CannotRealizeException
{
this(file.toURL());
}
public void play()
{
audioPlayer.start();
}
public void stop()
{
audioPlayer.stop();
audioPlayer.close();
}
}
TestCase.java
import java.io.File;
import java.io.IOException;
import javax.media.CannotRealizeException;
import javax.media.NoPlayerException;
public class TestCase
{
/**
* @param args
*/
public static void main(String[] args)
{
File audioFile = new File("demo.mp3");
try
{
SimpleAudioPlayer player = new SimpleAudioPlayer(audioFile);
System.out.println("music begin");
player.play();
System.out.println("music end");
} catch (NoPlayerException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CannotRealizeException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
在項(xiàng)目根目錄下面放置一個(gè)demo.mp3文件,最后整個(gè)項(xiàng)目變成:

右鍵點(diǎn)擊項(xiàng)目,run as java application

設(shè)置好運(yùn)行環(huán)境

成功!
發(fā)現(xiàn)很有趣。整個(gè)application運(yùn)行完了,但是音樂(lè)還在繼續(xù)。估計(jì)內(nèi)部開(kāi)了線(xiàn)程。
Oops! JSF Quick Start!
Purpose:
學(xué)習(xí)使用一個(gè)JSF
Precondition:
/Files/pixysoft/jsf_simple_lib.part1.rar
/Files/pixysoft/jsf_simple_lib.part2.rar
Reference:
http://www.exadel.com/tutorial/jsf/jsftutorial-kickstart.html#compile
Tutorial:
新建一個(gè)項(xiàng)目Dynamic Web Project,名字Oops_JSF

在lib目錄下添加以下jar文件

修改web.xml
<?xml version="1.0"?>
<!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>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
在WEB-INF目錄下面添加文件faces-config.xml
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<navigation-rule>
<from-view-id>/pages/inputname.jsp</from-view-id>
<navigation-case>
<from-outcome>greeting</from-outcome>
<to-view-id>/pages/greeting.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>personBean</managed-bean-name>
<managed-bean-class>jsfks.PersonBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
在WebContent下面添加pages目錄,然后新建2個(gè)文件
greeting.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>
<html>
<head>
<title>greeting page</title>
</head>
<body>
<f:view>
<h3>
<h:outputText value="#{msg.greeting_text}"/>,
<h:outputText value="#{personBean.personName}"/>
<h:outputText value="#{msg.sign}"/>
</h3>
</f:view>
</body>
</html>
inputname.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>
<html>
<head>
<title>enter your name page</title>
</head>
<body>
<f:view>
<h1>
<h:outputText value="#{msg.inputname_header}"/>
</h1>
<h:form id="helloForm">
<h:outputText value="#{msg.prompt}"/>
<h:inputText value="#{personBean.personName}"/>
<h:commandButton action="greeting" value="#{msg.button_text}"/>
</h:form>
</f:view>
</body>
</html>
在WebContent目錄下面添加一個(gè)index.jsp文件
<html>
<body>
<jsp:forward page="/pages/inputname.jsf" />
</body>
</html>
在src目錄下面添加jsfks目錄,再添加PersonBean.java文件
package jsfks;
publicclass PersonBean {
String personName;
/**
*@returnPersonName
*/
public String getPersonName() {
returnpersonName;
}
/**
*@paramPersonName
*/
publicvoid setPersonName(String name) {
personName = name;
}
}
在jsfks目錄下添加bundle目錄,再添加文件messages.properties
inputname_header=JSFKickStart
prompt=Tellusyourname:
greeting_text=WelcometoJSF
button_text=SayHello
sign=!
最后整個(gè)文件夾為:

最后Run as … On Server

注意:一定要把之前的server配置刪除,run as 的時(shí)候是一個(gè)新的server,就因?yàn)檫@個(gè)原因我忙了幾個(gè)小時(shí),才發(fā)現(xiàn)出錯(cuò)是因?yàn)橹按嬖诹肆硗庖粋€(gè)roject在server上,也不提示。
Oops! JSP + XML Quick Start
/Files/pixysoft/xalan.part1.rar
/Files/pixysoft/xalan.part2.rar
新建一個(gè)Dynamic Web Project,名叫Oops_jsp_xml,然后在lib下添加以下jar文件,都可以在JSTL包里面找到。(xalan.jar文件這里下載,解壓出來(lái))。在WEB-INF下新建tlds目錄,添加c.tld文件。

修改web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
在WebContent目錄下面添加2個(gè)文件:
student.xml
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student id="1">
<name>
<first name="Joe1">Joe</first>
<last name="y1">Y</last>
<middle name="t1">T</middle>
</name>
<grade>
<points>99</points>
<letter>A</letter>
</grade>
</student>
<student id="2">
<name>
<first name="james1">James</first>
<last name="todd">Todd</last>
<middle name="k1">K</middle>
</name>
<grade>
<points>92</points>
<letter>B</letter>
</grade>
</student>
<student id="3">
<name>
<first name="kate1">Kate</first>
<last name="wang1">Wang</last>
<middle name="a1">A</middle>
</name>
<grade>
<points>72</points>
<letter>C</letter>
</grade>
</student>
</students>
index.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<html>
<head>
<title>index</title>
</head>
<body>
<c:import var="students" url="student.xml" />
<x:parse var="doc" xml="${students}"/>
<table border="1">
<tr>
<th>First</th>
<th>Last</th>
<th>Points</th>
<th>Letter</th>
</tr>
<x:forEach var="student" select="$doc/students/student">
<tr>
<td><x:out select="name/first/@name" /></td>
<td><x:out select="name/last" /></td>
<td><x:out select="grade/points" /></td>
<td><x:out select="grade/letter" /></td>
</tr>
</x:forEach>
</table>
</body>
</html>
運(yùn)行!

Oops! JSTL Quick Start
Purpose:
掌握jstl入門(mén)
Precondition:
eclipse-java-europa-win32.zip
/Files/pixysoft/jakarta-taglibs-standard-current.zip
Tutorial
新建一個(gè)Dynamic Web Project,名字叫做Oops_jstl

在WebContent/WEB-INF/lib下添加以下jar文件,全部可以在jakarta-taglibs-standard-current.zip里面找到。

在webContent/WEB-INF下新建一個(gè)tlds目錄,添加以下文件

修改web.xml,添加以下內(nèi)容
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
在WebContent目錄下面添加index.jsp文件
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:if test="${pageContext.request.method=='POST'}">
<c:if test="${param.guess=='java'}">You guessed it!
<br />
<br />
</c:if>
<c:if test="${param.guess!='java'}">
You are wrong
<br />
<br />
</c:if>
</c:if>
<form method="post">Guess what computer language
I am thinking of?
<input type="text" name="guess" />
<input type="submit" value="Try!" />
<br />
</form>
</body>
</html>
運(yùn)行!

成功!

Oops! Eclipse + Hibernate Quick Start
Purpose:
學(xué)會(huì)使用Hibernate
Precondition:
eclipse-java-europa-win32.zip
hibernate-3.2.5.ga.zip
mysql-5.0.45-win32.zip
Quick Start:
在mySql數(shù)據(jù)庫(kù)里面添加一張表。

對(duì)應(yīng)的sql語(yǔ)句是:
CREATE TABLE CUSTOMER(
CID INTEGER,
USERNAME VARCHAR(12) NOT NULL,
PASSWORD VARCHAR(12)
);
ALTER TABLE CUSTOMER ADD CONSTRAINT PK PRIMARY KEY(CID);
在eclipse里面新建一個(gè)java project, 項(xiàng)目名為:Oops_hibernate

新建一個(gè)lib目錄,在lib目錄下面添加以下jar包,全部可以在hibernate.zip文件里面找到

選擇project – properties – java build path – libraries – add jars

把Oops_hibernate目錄下面的所有lib加進(jìn)來(lái)

在src目錄下面添加以下文件:

Customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="id" column="CID">
<generator class="increment" />
</id>
<property name="username" column="USERNAME" />
<property name="password" column="PASSWORD" />
</class>
</hibernate-mapping>
Customer.java
public class Customer {
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public String getPassword() {
return password;
}
public String getUsername() {
return username;
}
public void setId(int id) {
this.id = id;
}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
}
hibernate.cfg.xml,注意紅色部分要和數(shù)據(jù)庫(kù)對(duì)應(yīng)。
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.username">
root
</property>
<property name="connection.password">
admin
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping resource="Customer.hbm.xml" />
</session-factory>
</hibernate-configuration>
Test.java
import org.hibernate.*;
import org.hibernate.cfg.*;
public class Test {
public static void main(String[] args) {
try {
SessionFactory sf =
new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
for (int i = 0; i < 200; i++) {
Customer customer = new Customer();
customer.setUsername("customer" + i);
customer.setPassword("customer");
session.save(customer);
}
tx.commit();
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}
}
右鍵點(diǎn)擊項(xiàng)目,Run as – java application

在窗口選擇Test

運(yùn)行,完成!

Oops! Jsp + MS Access Quick Start!
20070908 最新update
如果使用相對(duì)路徑,需要修改鏈接字符串,轉(zhuǎn)化成為絕對(duì)路徑。
例如demo.mdb放在網(wǎng)站項(xiàng)目的根目錄,Oops_JSP_Javabean_Access/demo.mdb,則
String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+ request.getRealPath("demo.mdb");
可以發(fā)現(xiàn)此時(shí)數(shù)據(jù)層需要request提供realpath,因此需要從頁(yè)面上層(或者servlet)傳遞進(jìn)來(lái)。
目的
通過(guò)jsp鏈接access數(shù)據(jù)庫(kù),進(jìn)行查詢(xún)
前期條件
eclipse-java-europa-win32.zip
apache-tomcat-5.5.23.exe
tomcatPluginV31.zip
正文
在c:盤(pán)下面新建一個(gè)access數(shù)據(jù)庫(kù),名字為demo.mdb.

打開(kāi)demo.mdb數(shù)據(jù)庫(kù),建立以下表結(jié)構(gòu),和數(shù)據(jù)


新建一個(gè)Dynamic Web Project, 名字叫Oops_JSP_Javabean_Access
在src下建目錄beanbase,再建文件

BeanbaseBean.java
要非常注意鏈接數(shù)據(jù)庫(kù)的字段:
String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\demo.mdb";
這里使用絕對(duì)路徑指向demo.mdb數(shù)據(jù)庫(kù)
package beanbase;
import java.sql.*;
public class BeanbaseBean
{
private String timess = "";
Connection conn = null;
ResultSet rs = null;
String url = "jdbc:odbc:demo";
String sql;
public void adduser() throws Exception
{
try
{
String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\demo.mdb"; // DataBase是Access
// MDB文件的主文件名
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(sourceURL);
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// conn = DriverManager.getConnection(url, "", "");
Statement stmt = conn.createStatement();
sql = "select * from user2 where datess='" + timess + "'";
rs = stmt.executeQuery(sql);
while (rs.next())
{
System.out.println(rs.getString(1) + "succeed");
}
} finally
{
conn.close();
}
}
// Access sample property
public String gettimess()
{
return timess;
}
// Access sample property
public void settimess(String newValue)
{
if (newValue != null)
{
timess = newValue;
}
}
}
在WebContent下面建立2個(gè)jsp文件

beanase.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<body>
<form method="post" action="doneuser.jsp">
<input type="text" name="timess">
</form>
</body>
</html>
doneuser.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<jsp:useBean id="beanbaseBeanId" scope="session" class="beanbase.BeanbaseBean" />
<jsp:setProperty name="beanbaseBeanId" property="*" />
<body>
<jsp:getProperty name="beanbaseBeanId" property="timess" />
<%beanbaseBeanId.adduser();%>
</body>
</html>
右鍵點(diǎn)擊項(xiàng)目,run as – server

在瀏覽器輸入:
http://localhost:8080/Oops_JSP_Javabean_Access/beanbase.jsp

在頁(yè)面輸入:
Dr.Oops
回車(chē),得到結(jié)果!

查看Console的輸出:
Oops! JSP+Java Bean Quick Start!
eclipse europa + tomcat 5.5
Purpose:
完成這個(gè)項(xiàng)目,能夠?qū)κ褂胘sp + javabean
Prerequisite:
eclipse-java-europa-win32.zip
apache-tomcat-5.5.23.exe
tomcatPluginV31.zip
Reference:
http://www.tkk7.com/pixysoft/archive/2007/08/29/141048.html
Chapter 01
新建一個(gè)Dynamic Web Project, 名字叫Oops_JSP_Javabean

在src目錄下建立一個(gè)count目錄,增加一個(gè)java文件

counter.java
package count;
public class counter{
int count=0;
public counter(){}
public int getCount(){
count++;
return count;
}
public void setCount(int count){
this.count=count;}
}
在WebContent下面增加一個(gè)文件

counter.jsp
<html>
<body>
<jsp:useBean id="bean0" scope="application" class="count.counter"/>
<%
out.println("The Counter is : "+ bean0.getCount() +"<br>");
%>
</body>
</html>
右鍵點(diǎn)擊項(xiàng)目,run as – server

在瀏覽器輸入:

刷新幾次能夠看見(jiàn)變化!
無(wú)聊吠一下有時(shí)候很討厭互聯(lián)網(wǎng)(說(shuō)到實(shí)質(zhì),就是討厭一些人的人品)。google到一些有用資料,一點(diǎn)擊下載,不是注冊(cè)會(huì)員,就是交錢(qián)。媽的,你這么缺錢(qián)啊。簡(jiǎn)直惡心。
還有看了有些博客,說(shuō)什么xxx+spring + hibernate教程,什么非常優(yōu)秀。一打開(kāi),不是要email,就是聯(lián)系qq,壓根就沒(méi)把內(nèi)容帖出來(lái)。md你這么想收集人的email是不是啊。
還有些人,一打開(kāi)blog,仿佛很繁華,一堆程序下載,還有一堆好像是馬甲的在跟帖,吹的神乎其神。靠,下載后,隨便運(yùn)行一下就是一堆fatal error,直接導(dǎo)致關(guān)機(jī)。你丫的懂不懂編程的,連基本的程序結(jié)構(gòu)都不同,連異常都不會(huì)拋,連基本的備選流use case都不知道。還什么xxx數(shù)據(jù)庫(kù)框架,xxx持久層,惡心。
有些人就是惡心。什么狗屁資料,不就也是從internet上搜的,你算條毛。
去 codeproject看看,什么叫差異,什么叫道德差異。程序員,要從做人開(kāi)始學(xué)起。
Oops! Spring Framework Quick Start!
eclipse europa + tomcat 5.5+spring 2.06+lomboz S3.3RC1
Purpose:
完成這個(gè)項(xiàng)目,能夠?qū)pring框架有個(gè)整體認(rèn)識(shí),包括IoC之類(lèi)的。
Prerequisite:
eclipse-java-europa-win32.zip
apache-tomcat-5.5.23.exe
tomcatPluginV31.zip
spring-framework-2.0.6-with-dependencies.zip
org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip
Reference:
http://www.tkk7.com/pixysoft/archive/2007/08/29/141048.html
Chapter 01
新建一個(gè)Java Project,項(xiàng)目名為OopsSpringFramework

選擇project – properties – Libraries添加以下類(lèi)庫(kù)。所有類(lèi)庫(kù)可以在spring-framework-2.0.6.zip里面找到,包括dist目錄和lib目錄里面。

在src目錄下面添加以下文件:

beanRefDataAccess.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloWorldDAO1" class="HelloWorld1" />
<bean id="helloWorldDAO2" class="HelloWorld2" />
</beans>

beanRefFactory.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="beanFactory"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>beanRefDataAccess.xml</value>
<value>beanRefService.xml</value>
<value>beanRefMVC.xml</value>
</list>
</constructor-arg>
</bean>
</beans>
beanRefMVC.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloWorldMVC1" class="HelloWorld1" />
<bean id="helloWorldMVC2" class="HelloWorld2" />
</beans>
beanRefService.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloWorld1" class="HelloWorld1" />
<bean id="helloWorld2" class="HelloWorld2" />
<bean id="springDemoConstructor" class="SpringDemoConstructor">
<constructor-arg>
<value>Spring IDE Constructor</value>
</constructor-arg>
<property name="helloWorld">
<ref bean="helloWorld1"></ref>
</property>
</bean>
<bean id="springDemoSetter" class="SpringDemoSetter">
<property name="hello" value="Spring IDE Setter" />
<property name="helloWorld">
<ref bean="helloWorld2"></ref>
</property>
</bean>
</beans>
HelloWorld1.java
public class HelloWorld1 implements IHelloWorld
{
public HelloWorld1()
{
super();
}
public String sayHelloWorld()
{
return "Hello World HelloWorld1";
}
}
HelloWorld2.java
public class HelloWorld2 implements IHelloWorld
{
public HelloWorld2()
{
super();
}
public String sayHelloWorld()
{
return "Hello World HelloWorld2";
}
}
IHelloWorld.java
public interface IHelloWorld
{
String sayHelloWorld();
}
ISpringDemo.java
public interface ISpringDemo
{
IHelloWorld getHelloWorld();
String getHello();
}
ServiceFactory.java
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;
public final class ServiceFactory
{
private static BeanFactoryLocator bfLocator = null;
private static BeanFactoryReference bfReference = null;
private static BeanFactory factory = null;
static
{
bfLocator = SingletonBeanFactoryLocator.getInstance();
bfReference = bfLocator.useBeanFactory("beanFactory");
factory = bfReference.getFactory();
}
private ServiceFactory()
{
super();
}
public static Object getBeanByName(final String beanName)
{
return factory.getBean(beanName);
}
}
SpringDemoConstructor.java
public class SpringDemoConstructor implements ISpringDemo
{
private String hello;
private IHelloWorld helloWorld;
public SpringDemoConstructor(String hello)
{
this.hello = hello;
}
public String getHello()
{
return hello;
}
public IHelloWorld getHelloWorld()
{
return helloWorld;
}
public void setHelloWorld(IHelloWorld helloWorld)
{
this.helloWorld = helloWorld;
}
}
SpringDemoSetter.java
public class SpringDemoSetter implements ISpringDemo
{
private String hello;
private IHelloWorld helloWorld;
public String getHello()
{
return hello;
}
public void setHello(String hello)
{
this.hello = hello;
}
public IHelloWorld getHelloWorld()
{
return helloWorld;
}
public void setHelloWorld(IHelloWorld helloWorld)
{
this.helloWorld = helloWorld;
}
}
SpringIDETest.java
import junit.framework.TestCase;
public class SpringIDETest extends TestCase
{
private IHelloWorld helloWorld = null;
private ISpringDemo springDemo = null;
private final static String hello1 = "Hello World HelloWorld1";
private final static String hello2 = "Hello World HelloWorld2";
private final static String helloset = "Spring IDE Setter";
private final static String hellocon = "Spring IDE Constructor";
public void testSpringBeans()
{
helloWorld = (IHelloWorld) ServiceFactory.getBeanByName("helloWorld1");
assertEquals(hello1, helloWorld.sayHelloWorld());
helloWorld = (IHelloWorld) ServiceFactory.getBeanByName("helloWorld2");
assertEquals(hello2, helloWorld.sayHelloWorld());
}
public void testIoCConstructor()
{
// Constructor
springDemo = (ISpringDemo) ServiceFactory
.getBeanByName("springDemoConstructor");
assertEquals(hellocon, springDemo.getHello());
assertEquals(hello1, springDemo.getHelloWorld().sayHelloWorld());
}
public void testIoCSetter()
{
// Setter
springDemo = (ISpringDemo) ServiceFactory
.getBeanByName("springDemoSetter");
assertEquals(helloset, springDemo.getHello());
assertEquals(hello2, springDemo.getHelloWorld().sayHelloWorld());
}
}
鼠標(biāo)右點(diǎn)擊OopsSpringFramework,選擇 Add Spring Project Nature

打開(kāi)Spring Explorer窗口

在SpringExplorer里面右選擇項(xiàng)目,properties.

選擇Beans Support,Add xml

之后得到以下內(nèi)容

選擇Config Sets,New,輸入以下內(nèi)容

之后Spring-Explorer出現(xiàn)以下內(nèi)容

右鍵點(diǎn)擊項(xiàng)目,選擇Run as.. JUnit …

完成!
Oops! Eclispe Quick Start!Introduction:本章主要介紹搭建一個(gè)能夠開(kāi)發(fā)java的環(huán)境。
Chapter X
Eclipse最新版本 eclipse-java-europa-win32.zip
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/20070702/eclipse-java-europa-win32.zip&r=1&protocol=httpTomcat 5.5 一個(gè)服務(wù)器
http://apache.mirror.phpchina.com/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.zipTomcatPluginV31 插件
/Files/pixysoft/tomcatPluginV31.zipLomboz插件
http://download.forge.objectweb.org/lomboz/org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zipor
http://download.fr2.forge.objectweb.org/lomboz/org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zipmySQL database
http://dev.mysql.com/downloads/mysql/5.0.html#win32mySQL Connector java鏈接mysql的驅(qū)動(dòng)程序
http://dev.mysql.com/downloads/connector/j/5.0.htmlChapter Y 安裝
把eclipse解壓出來(lái)。
安裝Tomcat,根據(jù)提示。
把TOmcatPluginV31插件解壓到和eclipse一樣的目錄。
解壓lomboz插件,和上面方法一樣。
run eclipse.exe

安裝成功!
安裝mySQL
現(xiàn)在一個(gè)比較初級(jí)的java開(kāi)發(fā)環(huán)境已經(jīng)搭建起來(lái)了。