2010年10月4日 星期一

Linux配置mongoDB

MongoDB下載頁面
Step1.下載mongoDB
:~Downloads$ wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.6.3.tgz

Step2.解壓
~Downloads$ tar xzf mongodb-linux-x86_64-1.6.3.tgzls

Step3.更改目錄名稱
~Downloads$ mv mongodb-linux-x86_64-1.6.3 mongodb

Step4.移動資料夾至/opt
~Downloads$sudo mv mongodb /opt

Step5.建立給予mondoDB使用的資料夾
/$ sudo mkdir -p /data/db/
//mongoDB預設使用資料庫路徑為 /data/db
//linux習慣會將常變動資料置放於 /var下,因此可以將data/db移至/var下使用。
Step6.修改資料夾權限
sudo chown [檔案擁有者] [目標對象]
sudo chown jeffrey /data/db
Step7.執行MongoDB
//如此會啟動mongoDB,但需要使用另外一使用者環境,使用不同使用者登入才能操作mongoDB
./opt/mongod --dbpath=/data/db


//如此可在原本使用者環境中開啟mongoDB
 ./mongod --fork  --dbpath=/data/db --logpath=/opt/mongodb/log/mongodb.log --logappend




查詢MongoDB是否運行
  • ps -ef|greap grep mongod
查詢mongodb的Port Number是否運作
  • netstat -an -t|greap grep 28017
mongoDB預設Port是28017,再啟動時可以使用--port來指定使用port

Linux上配置TomCat6.0

連結資料:
Tomcat官網

安裝JDK:
安裝Tomcat前請先安裝好JDK
配置步驟:
Step1.下載tomcat6.0
sudo wget http://apache.cdpa.nsysu.edu.tw//tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz

版本請依實際下載你所需要版本(這裡用的是Core的版本)

Step2.解壓
sudo tar xvzf apache-tomcat-6.0.29.tar.gz

Step3.目錄更名

sudo mv apache-tomcat-6.0.29 /opt/tomcat6

Step4.啟動tomcat
執行/opt/tomcat/bin/底下的startup.sh
:/opt/tomcat6/bin$ ./startup.sh

//如果執行不起來,就做第五步(檔案群組權限問題)
Step5.修改檔案群組與權限
chgrp [參數] [群組名] [檔案路徑]
  • sudo chgrp -R jeffrey /opt/tomcat

chmod [參數] [檔案權限] [檔案目標]
  • sudo chmod -R 771 /opt/tomcat6

2010年10月3日 星期日

Linux 上配置JAVA JDK

§Linux上配置JDK
Sun JAVA JDK 1.6下載頁
因為已經被Oracle吃掉所以官網改成 Oracle JAVA
Oracle Sun Java SE JDK

JDK 下載點
Java SE Development Kit 6u21
 jdk-6u21-linux-x64-rpm.bin
Java SE Development Kit 6u21
 jdk-6u21-linux-x64.bin

這篇文章是使用jdk-6u21-linux-x64.bin
Step1.下載JDK
用你習慣的方式下載JDK,由於是Ubuntu你可以直接開瀏覽器下載,用瀏覽器直接下載可以在home/Downloads裡看到jdk-6u21-linux-x64這個檔案,你也可在命令列中使用wget命令來下載,如


:~/Downloads$ wget -O jdk-6u21-linux-x64.bin http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u21-linux-x64.bin?BundledLineItemUUID=F6qJ_hCxDsYAAAErUi0F_HEN&OrderID=.VqJ_hCx4egAAAErOS0F_HEN&ProductID=xKiJ_hCySHIAAAEpT7wzBGsB&FileName=/jdk-6u21-linux-x64.bin


wget -O jdk-6u21-linux-x64.bin 如此可以將下載後的檔案存成 jdk-6u21-linux-x64.bin

Step2.將檔案移至/opt中
:~/Downloads$ sudo mv jdk-6u21-linux-x64.bin /opt

過程中會問你管理者密碼,輸入後即可搬移


Step3.更改檔案權限

:/opt$ chmod +x jdk-6u21-linux-x64.bin 

Step4.解壓縮
:/opt$ sudo ./ jdk-6u21-linux-x64.bin 


這個檔案執行後會自解壓縮,以上執行完畢可以在opt下看到一個jdk1.6.0_21的資料夾。

Step5.建立Java資料夾
  • :/opt$ sudo mkdir java
Step6.將jdk1.6.0_21移到java資料夾下
此步可以省略,只是個人習慣,方便日後若是有java系列的東西方便放一起管理,例如JRE。
  • /opt$ sudo mv jdk1.6.0_21 java
Step7.設定環境變數
  • :/opt$ sudo nano /etc/profile
或
  • :/opt$ sudo gedit /etc/profile
在文件最尾端輸入
#java environment 
export JAVA_HOME=/opt/java/jdk1.6.0_21
export CLASSPATH=.:./classes:../classes:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin


Step8.
  • source /etc/profile
Step9.重新啟動Linux

Step10.測試java是否啟動







~$ java -version







參考資料
http://tsjianxin.blog.51cto.com/1309817/355384
http://tw.myblog.yahoo.com/jw!q5yoQbKZG0AAcnvqqbxB/article?mid=16
http://tech.techweb.com.cn/thread-226426-1-1.html
http://doflower.blogspot.com/2009/05/linuxjava-classpath.html
http://freelon.pixnet.net/blog/post/30820017


關於環境變數的profile檔功用可以參考鳥哥網站,鳥哥介紹的很清楚真是功德無量
http://linux.vbird.org/linux_basic/0320bash.php#settings_bashrc

2010年9月8日 星期三

Ubuntu 10.04 install Java6 (apt)

Ubuntu 10.04是預設是使用open java,如果要程式開發還是需要安裝Sun Java,以下是Ubuntu環境安裝Java6的過程記錄。

Step1.
sudo add-apt-repository "deb http://archive.canonical.com/ubuntu lucid partner"

這一行其實就是編輯了apt裡的sources.list
sources.list path
/etc/apt/sources.list

利用文字編輯器打開sources.list,拉到最下方,可以看到sources.list裡面被加入了
"deb http://archive.canonical.com/ubuntu lucid partner"




Step2.更新套件
  • sudo apt-get update
Step3.安裝java jre
  • sudo apt-get install sun-java6-jre sun-java6-plugin
Step4.安裝java jdk
  • sudo apt-get install sun-java6-jdk sun-java6-plugin
Step5.查詢java jdk版本
  • java -version


參考資料
ubunt社群
http://wiki.ubuntu.org.cn/index.php?title=Sun-java6&variant=zh-tw

IT開發者Blog
http://www.dotblogs.com.tw/bowwowxx/archive/2010/06/11/15794.aspx
http://hi.baidu.com/xlmeng1988/blog/item/2dce52ae73ef26f3faed50d2.html
http://askcuix.javaeye.com/blog/178819

2010年8月20日 星期五

Deprecated metadata tag



用法:
[Deprecated("string_describing_deprecation")]
[Deprecated(message="string_describing_deprecation")]
[Deprecated(replacement="string_specifying_replacement")]
[Deprecated(replacement="string_specifying_replacement", since="version_of_replacement")]

原文(引用自adobe flex4 help):
A class or class element marked as deprecated is one which is considered obsolete, and whose use is discouraged in the current release. While the class or class element still works, its use can generate compiler warnings

一個類別或是類別中的項目被標記成Deprecated表示此項目是過時的、廢棄的、不建議使用的,不鼓勵使用在當前的釋出版本。雖然被宣告廢棄的Class或Class中的項目仍然工作,但能讓編譯器產生警告提醒。

The mxmlc command-line compiler supports the show-deprecation-warnings compiler option, which, when true, configures the compiler to issue deprecation warnings when your application uses deprecated elements. The default value is true.

Insert the [Deprecated] metadata tag before a property, method, or class definition to mark that element as deprecated. The [Deprecated] metadata tag has the following options for its syntax when used with a class, property or method:
 
功用:

  • 標記已經廢棄的Class以免誤用,若使用編譯器會出現警告提醒。
範例:
//宣告method已經廢棄,並提示改用建議的method
package com
{
 import spark.components.Group;
 public class MyDeprecatedGroup extends Group
 {
  public function MyDeprecatedGroup()
  {
   super();
  }  
  private var _topGap:Number; 
  //宣告topGap廢棄,並建議使用topPixels
  [Deprecated(replacement="MyDeprecatedGroup.topPixels")] 
  public function set topGap(value:Number):void
  {
   _topGap = value;
  }
  public function get topGap():Number
  {
   return _topGap;
  }
 }
}  
//Application
<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
applicationComplete="application1_applicationCompleteHandler(event)" xmlns:com="com.*"
>
<fx:Script\>
<![CDATA[ 
]]>
</fx:Script>
<com:MyDeprecatedGroup>
 <com:topGap>1.0</com:topGap>  
</com:MyDeprecatedGroup>
</s:Application>   
訊息警告如下圖:
 
 
 
 
 
 

  • Event,Effect,Style,metadata tags也支援 deprecation功能

文件
The [Event], [Effect] and [Style] metadata tags also support deprecation. These tags support the following options for syntax:
 
在Event,Effect,Style的metadata tags中,也都支持deprecation的宣告,用法如下
 
用法
[Event(... , deprecatedMessage="string_describing_deprecation")]
[Event(... , deprecatedReplacement="change2")]
[Event(... , deprecatedReplacement="string_specifying_replacement", deprecatedSince="version_of_replacement")]

DefaultProperty metadata tag


用法:
[DefaultProperty("propertyName")]

原文:
The [DefaultProperty] metadata tag defines the name of the default property of the component when you use the component in an MXML file.

功用說明:
[DefaultProperty]標籤用來定義組件中的預設屬性,對應於MXML標籤檔上使用。

範例:
//這個範例將預設屬性改成selected,原本在toggleButtong上的預設屬性是label。
//myButton.as
package com
{

 import spark.components.ToggleButton;

 [DefaultProperty("selected")]
 public class myButton extends ToggleButton
 {
  public function myButton()
  {
   super();
  }
//mxml設定進來的值在此可以抓到並處理
  override public function set selected(value:Boolean):void
  {
   if(value != super.selected)
   super.selected = value;
  } 

 }

}
//mxml檔中使用ToggleButton與myButton來驗證結果
<s:Group layout="{new VerticalLayout()}">
<s:ToggleButton>true</s:ToggleButton> //預設屬性是label因此會出現true
<com:myButton>true</com:myButton>     //預設屬性是selected因此出現按下
</s:Group>












例外使用的狀況:
The one place where Flex prohibits the use of a default property is when you use the ActionScript class as the root tag of an MXML component. In this situation, you must use child tags to define the property, as the following example shows

主要是說,若是mxml做為根標籤,就無法直接在標籤中輸入文字使用預設值,而是須將改預設值名稱當成mxml標籤來呼叫使用。

當然這就是在說將Class做成mxml組件檔時的情境,範例如下:
//myButtonC.mxml
<?xml version="1.0" encoding="utf-8"?>
<com:myButton xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:com="com.*">
<!--當成root標籤使用時,預設屬性設定改用標籤呼叫設定。-->
 <com:selected>true</com:selected>
</com:myButton> 

而這個組件放於Application上時,依然可以直接設定預設值如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
xmlns:com="com.*"
> 
<fx:Script>
<![CDATA[ 
import spark.layouts.VerticalLayout;
]]>
</fx:Script>
<s:Group layout="{new VerticalLayout()}">
<com:myButtonC>true</com:myButtonC>
</s:Group>
</s:Application>


參考
http://help.adobe.com/zh_CN/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html

//查詢Creating a default property
http://help.adobe.com/zh_CN/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-79f7.html#WS2db454920e96a9e51e63e3d11c0bf69084-79fa

英文原文引用自adobe flex4 help文件

2010年8月19日 星期四

ArrayElementType Metadata tag


原文:
Using Flex4說明手冊中關於ArrayElementType的說明:
When you define an Array variable in ActionScript, you specify Array as the data type of the variable. However, you cannot specify the data type of the elements of the Array.

當你於ActionScript中定義一個Array變數,你指定Array為資料型態,然而你無法指定Array內項目的資料型態。
(在AS3中Vector可以指定陣列中項目的資料型態,Array本身沒有此項功能)

功用:
To allow the Flex MXML compiler to perform type checking on Array elements, you can use the [ArrayElementType] metadata tag to specify the allowed data type of the Array elements, as the following example shows:

你可以藉由ArrayElementType這個metadata tag讓MXML compiler來檢查Array的項目元素是否為ArrayElementType指定資料格式的項目。

使用範例:
//Class
package com
{ 
 import spark.components.Group;
 public class myGroup extends Group
 {
  public function myGroup()
  {
   super(); 
  } 
  //標籤宣告
  [ArrayElementType("Number")]
  public var myArray:Array; 
 }
}

//mxml檔案中
<com:myGroup id="mg">
<com:myArray>
<fx:int>1.0</fx:int>   //此處會有編譯錯誤警告,因為使用<int>
</com:myArray>
</com:myGroup>   
note:
在mxml中若是對myArray使用非Number的項目就會出像錯誤警告,但是此項功能僅對於MXML標籤有作用,若你使用ActionScript來對myArray來操作,並加入非Number資料型態的項目並不會出像編譯警告。
  •  ArrayElementType("Number")]的宣告對ActionScript直接操作是無效的
//在application Complete事件發生後去操作myArray,並給予非Number的項目,是可以通過編譯的
protected function application1_applicationCompleteHandler(event:FlexEvent):void 
{
 mg.myArray.push( "test" );
}