Sunday, September 9, 2012

Build Maven Web Project from Eclipse

  •  Open your eclpse, New->Others, choose "Maven Project" and pres Next.
 
  •  Check "Create a simple project (skip archetype selection)" and press Next.
  • Fill "Group Id", "Artifact Id" fields, and choose "war" in Packaging drop list. 
  • Press Finish.
  • Since Maven didn't generate the web.xml, you have to build this file in path (src/main/java/webapp) manually.





    Tomcat Installation

    For Windows
    1. Download Tomcat package from http://tomcat.apache.org/download-60.cgi
    2. Unzip this file to generate corresponding folder (e.g., Tomcat)
    3. In Tomcat/bin, you can find the startup.bat file. 
    4. Double click statup.bat and use http://localhost:8080 for testing, as follows: 

    Install MySQL

    For windows: 
    1. Download Appserv (e.g., appserv-win32-2.5.10.exe) form http://www.appservnetwork.com/
    2. Double click appferv-win32-2.5.10.exe to install. 
    3. press next, next, then finish.
    4. Finally, you can use the http://localhost to check. 
      •  In the above page, you can click "phpMyAdmin Database Manger" to enter mysql server (admin type root, and password as your setting), as follows:









    Saturday, September 8, 2012

    Hibernate Code Generation

    Hibernate Code Generation
    • Before code generation, you have a database server includes database with some tables. Here, we have installed MySQL and built a database (i.e. chtrh) with some tables (i.e., user, stock). 
    • There are two required files and one console configuration (i.e., Hibernate Configuration File, Hibernate Reverse Engineering File, and Hibernate Console Configuration) for code generation.
      • Create Hibernate Configuration file and name as hibernate.cfg.xml, then press next.

      •  Set your database url, username and password, then press finish. 

      • Create Hibernate Console Configuration (maybe you can't find this file in eclipse). 
        • Here, you have to choose the location of hibernate.cfg.xml. 
        • Select the "Annotations (jdk 1.5+)" radio button, then press finish. 

      • Create Hibernate Reverse Engineering file and name as hibernate.reveng.xml then press next. 
      • In the "Type Mappings" tab, you can press "Refresh" botton, and you can get the database and its tables, in here, you can free choose table which to be generated code.
      • In the "Table Filters" tab, you can press "Refresh" button, and you can get the database and its tables, in here, you can also free choose table which to be generated code.
      •  In the "Table and Columns" tab, you can press "Add" button, and you can get the database and its tables, in here, you can also free choose table or columns which to be generated code.


      • After generating hibernate.cfg.xml and hibernate.reveng.xml files and hibernate console configuration. Switch to Hibernate perspective view, and choose Hibernate Code Generation Configuration function.

      •  In the "Console configuration" drop list, you can choose console configuration.
      • In the Exporters tab, you have to choose output type (usually select Domain code, Hibernate XML Mappings, DAO code). 
      • If you prefer use hibernate annotation, you have to check the "Use Java 5 syntax" and "Generated EJB3 annotations"
      • Lastly, after pressing run button, the hibernate will generate threes (i.e.,Domain code, Hibernate XML Mappings, DAO code ) file for each table. 

    Hibernate Eclipse Plugin

    Hibernate Eclipse Plugin
    • Open Eclipse Marketplace and input "Hibernate", you can see the following screen. 

    •  Install Hibernate Tools depend on you eclipse version. In this article, we choose eclipse Indigo. 
    • After installation, you can see the Hibernate button in your perspective view.
       
    • The next article will introduce how to automatically generate code. 

    Maven Installation

    For command line:
    • Set the Maven/bin in your path. 
    • Type "mvn --version" for testing, the output are showed in below: 
    •  C:\Users\Stanley_PC>mvn --version
      Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800)
      Java version: 1.6.0_24
      Java home: C:\Program Files\Java\jdk1.6.0_24\jre
      Default locale: zh_TW, platform encoding: MS950
      OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows

     For Eclipse Plug-in
    • Use the Eclipse Marketplace menu and input "Maven", you can get the following screen. 

    • Install the "m2eclipse-wtp: Maven Integration for Eclipse WTP" and  "Maven Integration for Eclipse", where WTP package for web project. 
    • Now, you can new a Maven project.