顯示具有 Development 標籤的文章。 顯示所有文章
顯示具有 Development 標籤的文章。 顯示所有文章

2015年4月29日 星期三

[教學] 建立 Python + django + MySQL 開發環境 for windows

由於接了一個用 django 開發的項目,所以簡單整理一下它開發環境設定方法:

軟體需求:

  1. Python for Windows
    (視乎版本需求,建議用32 bit 版本,因為小弟試用過64 bit 版本,會有不明的問題,所以放棄了) https://www.python.org/download/releases/2.7.6/
  2. pip (package manager for python)
    下載get-pip.py
    https://pip.pypa.io/en/latest/installing.html
  3. MySQL-python driver
    https://pypi.python.org/pypi/MySQL-python/1.2.5

安裝步驟:

  1. 安裝 python for windows
    image

    設定安裝目錄
    image
    image
  2. 設定好PATH 環境變數指向Python 根目錄
    image
  3. 安裝pip
    1. 開啟cmd (run as administrator),前往get-pip.py所在的目錄
       image
    2. 執行python get-pip.py
      image 
    3. 經過一輪下載後完成安裝
      image
  4. 安裝MySQL-Python Driver
    image
  5. 利用pip 安裝django
    1. 執行 python -m pip install django==1.2.6
      image
    2. 如預到以下這個問題,請按照這個網址修改Python 目錄下的Lib\mimetype.py
      http://bugs.python.org/review/9291/diff/1663/Lib/mimetypes.py
      image
    3. 經過一輪下載後安裝完成!
      image

2013年4月24日 星期三

[教學] 快速建立Tomcat Development Environment + 簡單 jsp 示範

本筆記是為一些有Java 經驗的朋友所寫,方便他們快速由頭開始建立好Tomcat 的開發環境,所以不懂Java 的朋友這篇文章或許不識合你。
另外本筆記依據小弟開發經驗所記下,由於現在用的開發環境已經用了好一陣子,所以我沒有由頭每一個步驟驗證,中間或有錯漏,有錯請指正!
Software Requirment:
1. Java EE 6 SDK
http://www.oracle.com/technetwork/java/javaee/downloads/index.html
2. Tomcat 6.0
http://tomcat.apache.org/download-60.cgi
3. Eclipse IDE for Java EE Developers
http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/junosr2
4. MySQL
主要是在本教學內的JSP 示範用,MySQL 的安裝教學我想不難在網絡上找到
5. MySQL JDBC Driver
http://dev.mysql.com/downloads/connector/j/
開發環境設定:
1. Setup Java EE (全部選 default setting 即可)
2. Unzip eclipse,打開eclipse.exe (Eclipse 是小弟常用的IDE,所以在本教學都會用eclipse 演示)
((VK8OBWHUELSO~I4NMNI~8

image
3. 先在Eclipse設定好一個Web Project 備用: Right click “Project Explorer”, 打開 New Project 選單,選擇 Dynamic Web Project ,做好一些簡單的設定
image
image
4. Eclipse 已經準備好了
image
5. 開始設定Tomcat: 打開Tomcat,先到conf folder 內,編輯tomcat-users.xml,這裡是tomcat manager 的使用者設定
2(M93ZC3(`E%J)E[[2YE]%X

6. 在lib folder 內放好JDBC Driver
WM6ESMYP89%P{Y9(N~T195A
7. 在<tomcat-users> 內插入以下使用者設定 (user=user1, password=welcome)

<role rolename="manager"/>
<role rolename="admin"/>
<user username="user1" password="welcome" roles="admin,manager"/> 

PB2`A2`0V4Y[4I)7RY8AXJF
8. 在tomcat 的bin folder 內,執行setclasspath.bat,最後執行startup.bat,你就會看到tomcat 在啓動了
image
 
9. 打開localhost:8080,看見老虎頭像就大功告成了
image

10. 現在假設MySQL 已經在本機安裝好,並有以下一個簡單的Database tutorial,裡面有一個Table tbl_tutorial,內容如下
image

11. 在Eclipse 的web project 裡,打開WebContent folder,然後新增一個jsp file (right click WebContent, New > JSP File)
image

12. 編輯JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ page import ="java.util.*" %>
<%@ page import ="java.lang.Number" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body> 
<% 

Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://<DB host>:<DB port>/tutorial","<DB user>","<DB password>");
Statement st= con.createStatement(); 

String sql = "SELECT name FROM tbl_tutorial;";
ResultSet rs=st.executeQuery(sql); 

while (rs.next()){
    out.println("Hello world! " + rs.getString(1) + "<br/>");
} 

%> 

</body>
</html>










13. 將完成好的web app 打包成war 檔案:right click web project, Export > WAR file
image

image
14. 登入Tomcat Manager (用step 7 的設定)
image
image

15. Deploy 剛剛 export 出來的WAR file
]{7301[DVOM0Z}D8_8(UDFV
M}U$OMPIEOL_M1V0S9`NHND

16. 打開http://localhost:8080/Tutorial/testing.jsp 你就會看到結果了!
image

17. 最後簡單介紹一下剛deploy 的web app 的folder structure

Depoly 後在webapps 底下就會自動生成一個project 名的folder
image

對應Eclipse 內WebContent folder 內的所有檔案都會被搬到這裡
image

WEB-INF folder 內主要放complie 好的java class,如果將來要寫servlet ,class file 就會被搬到 classes folder 內
而lib 則是用來放這個web app 專用的library
image










2011年8月9日 星期二

[教學] 在 eclipse 裡設定 JQuantLib 的開發環境 (Setup JQuantLib in eclipse)

工作需要,這幾天都在研究一套JAVA 的Quantative finance library – JQuantLib。
因為暫時只是在POC階段,所以先寫安裝方法,不寫這套library 的內容。

我的開發環境:

  • J2SE 1.5.0_22
  • Eclipse Helio (service release 2)

在eclipse 的設定方法 (假設大家都懂得如可在eclipse 加入新插件):

  1. 安裝 Maven Integration for Eclipse
    Maven 與 Eclipse 的 integration
    Eclipse update url:
    http://download.eclipse.org/technology/m2e/releases
  2. 安裝 Subversive
    打開 Help > Install New Software... > select Helios - http://download.eclipse.org/releases/helios > Collaboration Tools,安裝以下一堆plug-in
    clip_image002
    安裝完成後會有對話框詢問你要裝甚麼connector,我沒有理會,通通都把它裝起來。
    clip_image004
  3. 安裝 FingBugs
    Description: Tools that analyse your code and point out the place that you may got a bug or have a bad practise.
    Eclipse update url:
    http://findbugs.cs.umd.edu/eclipse/
  4. 安裝 PMD
    Description: Help to find bad constructions in the code, either those commonly known or those defined by JQuantLib.
    Eclipse update url:
    http://pmd.sf.net/eclipse
  5. 安裝 EclEmma
    Description: Tools for easy verify of the code coverage of your JUnit test cases.
    Eclipse update url:
    http://update.eclemma.org/
  6. 設定 JQuantLib SVN Repository
  7. Check out JQuantLib source
    • 打開Window > Show View > Others,點選 SVN Repositories
      clip_image012
    • SVN Repositories 的 view 入面,right click 剛新加入的repositories,然後選Find/Check Out As…
      clip_image014

    • 然後選 Check out as a project with the name specified:,然後按Finish
      clip_image016

    • Check out in progress ……
      clip_image018
    • 重覆以上步驟直到所有repositories 都check out 完成。
      clip_image020
    • 完成!

Reference:
http://www.jquantlib.org/index.php/JQuantLib_Users_Guide#Install_plugins
http://www.jquantlib.org/index.php/Checkout_in_Eclipse_with_SVN

2011年7月14日 星期四

Internet Component Download - INF File Architecture

Introduction

An information file (.inf) provide the installation instruction for IE to setup and register your software distribution. It consists of any number of name section. And each section can have multiple items.

Each section will have its own predefined purpose, such as updating the registry, executing a command, copying some file, etc.

Main Sections of an INF File in Internet Component Download:

  • [Add.Code]
    This section lists all the files to be installed, including optional files
    [Add.Code]
    filename1=section-name1
    filename2=section-name2

  • [Setup Hook]
    This section lists all hook that will be executed before setting up files in [Add.Code] section.
    [Setup Hooks]
    hookname1=section-name4
    hookname2=section-name5
    [hookname1]
    run=extrac32.exe /e /a /y /l c:\MyApplication\client MyApp.cab

  • [Version]
    For compatibility, the following lines must be added if we use hooks
    [Version]
    Signature="$CHICAGO$"
    AdvancedINF=2.0

  • [DefaultInstall]
    Installation section that is executed by default. Contains pointers to other sections specifying files to copy and delete, registry updates, .ini file updates, and so on. (for full list of pointer and the systax of this section please refer to here)
    In this post we will just talk about AddReg. AddReg pointer point to a section for adding subkeys or value names to the registory, optionally setting the value.

    [DefaultInstall]
    AddReg=AddRegSection
    [AddRegSection]
    HKLM,Software\MyApp,ProgramName,,"My Application"
    HKLM,Software\MyApp,"Program Location",,"%25%\MyApp.exe"

  • [Strings]
    Defines one or more strings keys. The Installer expands the strings key to the given string and uses it for further processing. You must enclose a strings key in percent signs (%).

    [String]
    String0=”MyApplication”
    String1=”Read me”


    Reference:
    Setup Information File (.inf) Definition
    About INF File Architecture

    2011年6月20日 星期一

    初探 Internet Component Download

    這幾天都在研究 "Internet Component Download” 的資料,以下是一些網上資料的整理 :

    MSDN offical defination
    Internet Component Download is a system service for downloading and installing software from Web sites on the Internet and intranets. This service also provides certificate checking. Internet Component Download is supported by Microsoft Internet Explorer 3.0 and later.
    You, the software provider or Web master, can "package" components and place them on your Web servers for download. When users visit your Web site, Internet Component Download enables their browsers to pull down and install the programs.
    Key Concept