posts - 32,comments - 8,trackbacks - 0

          Oops! JMF Quick Start

           

          Purpose:

          學習完后能夠學會操作JMF.

          JMFjava 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:

          新建一個java project,項目名為Oops_JMF

           

          在項目里面添加一個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();

                        }

           

                 }

           

          }




          在項目根目錄下面放置一個demo.mp3文件,最后整個項目變成:

           

           

          右鍵點擊項目,run as java application



           

          設置好運行環境



           

          成功!

           

          發現很有趣。整個application運行完了,但是音樂還在繼續。估計內部開了線程。


          posted @ 2007-09-07 14:56 張辰 閱讀(901) | 評論 (0)編輯 收藏
           

          Oops! JSF Quick Start!

          Purpose:

          學習使用一個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:

          新建一個項目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個文件

          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目錄下面添加一個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
          =!



          最后整個文件夾為:



          最后
          Run as … On Server




          注意:一定要把之前的
          server配置刪除,run as 的時候是一個新的server,就因為這個原因我忙了幾個小時,才發現出錯是因為之前存在了另外一個roject在server上,也不提示。

          posted @ 2007-09-04 18:39 張辰 閱讀(358) | 評論 (0)編輯 收藏

          Oops! JSP + XML Quick Start

          /Files/pixysoft/xalan.part1.rar
          /Files/pixysoft/xalan.part2.rar

          新建一個Dynamic Web Project,名叫Oops_jsp_xml,然后在lib下添加以下jar文件,都可以在JSTL包里面找到。(xalan.jar文件這里下載,解壓出來)。在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個文件:

          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>

          運行!


           

          posted @ 2007-09-02 02:21 張辰 閱讀(241) | 評論 (0)編輯 收藏
           

          Oops! JSTL Quick Start

          Purpose:

          掌握jstl入門

          Precondition:

          eclipse-java-europa-win32.zip

          /Files/pixysoft/jakarta-taglibs-standard-current.zip

          Tutorial

          新建一個Dynamic Web Project,名字叫做Oops_jstl



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



          webContent/WEB-INF下新建一個tlds目錄,添加以下文件



          修改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目錄下面添加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>



          運行!




          成功!

          posted @ 2007-09-01 20:09 張辰 閱讀(207) | 評論 (0)編輯 收藏
           

          Oops! Eclipse + Hibernate Quick Start

          Purpose:

          學會使用Hibernate

          Precondition:

          eclipse-java-europa-win32.zip

          hibernate-3.2.5.ga.zip

          mysql-5.0.45-win32.zip

          Quick Start:

          mySql數據庫里面添加一張表。



          對應的
          sql語句是:

          CREATE TABLE CUSTOMER(

          CID INTEGER,

          USERNAME VARCHAR(12) NOT NULL,

          PASSWORD VARCHAR(12)

          );

          ALTER TABLE CUSTOMER ADD CONSTRAINT PK PRIMARY KEY(CID);


          eclipse里面新建一個java project, 項目名為:Oops_hibernate


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


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

          Oops_hibernate目錄下面的所有lib加進來



          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
          ,注意紅色部分要和數據庫對應。

                   <?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();

                  }

              }

          }



          右鍵點擊項目,Run as – java application



          在窗口選擇
          Test





          運行,完成!


          posted @ 2007-09-01 14:57 張辰 閱讀(456) | 評論 (0)編輯 收藏
          Oops! Jsp +  MS Access Quick Start!

           

          20070908 最新update

          如果使用相對路徑,需要修改鏈接字符串,轉化成為絕對路徑。
          例如demo.mdb放在網站項目的根目錄,Oops_JSP_Javabean_Access/demo.mdb,則
          String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+ request.getRealPath("demo.mdb");
          可以發現此時數據層需要request提供realpath,因此需要從頁面上層(或者servlet)傳遞進來。




          目的

          通過jsp鏈接access數據庫,進行查詢

           

          前期條件

          eclipse-java-europa-win32.zip

          apache-tomcat-5.5.23.exe

          tomcatPluginV31.zip

           

          正文

          在c:盤下面新建一個access數據庫,名字為demo.mdb.

           

          打開demo.mdb數據庫,建立以下表結構,和數據

           

           

          新建一個Dynamic Web Project, 名字叫Oops_JSP_Javabean_Access

           

           

          在src下建目錄beanbase,再建文件


          BeanbaseBean.java

          要非常注意鏈接數據庫的字段:

          String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\demo.mdb";

          這里使用絕對路徑指向demo.mdb數據庫

           

          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個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>

           

           

          右鍵點擊項目,run as – server

           

           

           

          在瀏覽器輸入:

          http://localhost:8080/Oops_JSP_Javabean_Access/beanbase.jsp




          在頁面輸入:

          Dr.Oops

          回車,得到結果!




          查看Console的輸出:

          posted @ 2007-08-30 15:12 張辰 閱讀(544) | 評論 (0)編輯 收藏
           

           

          Oops! JSP+Java Bean Quick Start!


          eclipse europa + tomcat 5.5


          Purpose:

          完成這個項目,能夠對使用jsp + javabean

          Prerequisite:

          eclipse-java-europa-win32.zip

          apache-tomcat-5.5.23.exe

          tomcatPluginV31.zip


          Reference:

          http://www.aygfsteel.com/pixysoft/archive/2007/08/29/141048.html 

          Chapter 01

          新建一個Dynamic Web Project, 名字叫Oops_JSP_Javabean

           

           

          在src目錄下建立一個count目錄,增加一個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下面增加一個文件



          counter.jsp

           

          <html>

          <body>

          <jsp:useBean id="bean0" scope="application" class="count.counter"/>

          <%

          out.println("The Counter is : "+ bean0.getCount() +"<br>");

          %>

          </body>

          </html>

           

           

           

          右鍵點擊項目,run as – server

           

          在瀏覽器輸入:



          刷新幾次能夠看見變化!

          posted @ 2007-08-30 14:17 張辰 閱讀(268) | 評論 (0)編輯 收藏
          無聊吠一下




          有時候很討厭互聯網(說到實質,就是討厭一些人的人品)。google到一些有用資料,一點擊下載,不是注冊會員,就是交錢。媽的,你這么缺錢啊。簡直惡心。

          還有看了有些博客,說什么xxx+spring + hibernate教程,什么非常優秀。一打開,不是要email,就是聯系qq,壓根就沒把內容帖出來。md你這么想收集人的email是不是啊。

          還有些人,一打開blog,仿佛很繁華,一堆程序下載,還有一堆好像是馬甲的在跟帖,吹的神乎其神。靠,下載后,隨便運行一下就是一堆fatal error,直接導致關機。你丫的懂不懂編程的,連基本的程序結構都不同,連異常都不會拋,連基本的備選流use case都不知道。還什么xxx數據庫框架,xxx持久層,惡心。

          有些人就是惡心。什么狗屁資料,不就也是從internet上搜的,你算條毛。

          去 codeproject看看,什么叫差異,什么叫道德差異。程序員,要從做人開始學起。
          posted @ 2007-08-30 10:27 張辰 閱讀(217) | 評論 (1)編輯 收藏

          Oops! Spring Framework Quick Start!


          eclipse europa + tomcat 5.5+spring 2.06+lomboz S3.3RC1


          Purpose:

          完成這個項目,能夠對spring框架有個整體認識,包括IoC之類的。

          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.aygfsteel.com/pixysoft/archive/2007/08/29/141048.html 



          Chapter 01
           

          新建一個Java Project,項目名為OopsSpringFramework

           

           

           

          選擇project – properties – Libraries添加以下類庫。所有類庫可以在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());
              }
          }




          鼠標右點擊OopsSpringFramework,選擇 Add Spring Project Nature


           

          打開Spring Explorer窗口

           

           

           



          SpringExplorer里面右選擇項目,properties.



          選擇
          Beans Support,Add xml



           

          之后得到以下內容


           

          選擇Config SetsNew,輸入以下內容

           

          之后Spring-Explorer出現以下內容



          右鍵點擊項目,選擇Run as.. JUnit …

           


          完成!


          posted @ 2007-08-30 10:11 張辰 閱讀(891) | 評論 (0)編輯 收藏
          Oops! Eclispe Quick Start!



          Introduction:

          本章主要介紹搭建一個能夠開發java的環境。


          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=http

          Tomcat 5.5 一個服務器
          http://apache.mirror.phpchina.com/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.zip

          TomcatPluginV31 插件
          /Files/pixysoft/tomcatPluginV31.zip

          Lomboz插件
          http://download.forge.objectweb.org/lomboz/org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip
          or
          http://download.fr2.forge.objectweb.org/lomboz/org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip

          mySQL database
          http://dev.mysql.com/downloads/mysql/5.0.html#win32

          mySQL Connector java鏈接mysql的驅動程序
          http://dev.mysql.com/downloads/connector/j/5.0.html

          Chapter Y 安裝

          把eclipse解壓出來。

          安裝Tomcat,根據提示。

          把TOmcatPluginV31插件解壓到和eclipse一樣的目錄。

          解壓lomboz插件,和上面方法一樣。

          run eclipse.exe



          安裝成功!

          安裝mySQL

          現在一個比較初級的java開發環境已經搭建起來了。
          posted @ 2007-08-29 18:42 張辰 閱讀(394) | 評論 (0)編輯 收藏
          僅列出標題
          共4頁: 上一頁 1 2 3 4 下一頁 
          主站蜘蛛池模板: 兖州市| 剑阁县| 兰州市| 博爱县| 民乐县| 本溪市| 福安市| 宜昌市| 新津县| 阿坝县| 望城县| 兰溪市| 广平县| 呼图壁县| 延吉市| 苍山县| 康保县| 阳朔县| 辽宁省| 乌拉特后旗| 襄垣县| 剑川县| 秭归县| 石渠县| 伊宁县| 忻城县| 武隆县| 阳城县| 宁武县| 芜湖市| 孝昌县| 丰城市| 银川市| 白沙| 宣化县| 临夏县| 澎湖县| 宾阳县| 上饶县| 满洲里市| 莎车县|