顯示具有 Ubuntu學習 標籤的文章。 顯示所有文章
顯示具有 Ubuntu學習 標籤的文章。 顯示所有文章

2010年3月28日 星期日

在Ubuntu中設定Maven2

安裝Maven2前須先安裝Java,而Maven2只需透過下列指令即可安裝:
sudo apt-get install maven2

安裝完成後Maven2的設定檔會存放在/etc/maven2/,可在此目錄看到m2.conf及setting.xml,說明如下:
m2.conf:記錄Maven的Jar配置。
setting.xml:記錄Maven2的全域設定。

可輸入mvn -version如出下列資訊即表示安裝成功:

Apache Maven 2.2.1 (rdebian-1)
Java version: 1.6.0_15
Java home: /usr/lib/jvm/java-6-sun-1.6.0.15/jre
Default locale: zh_TW, platform encoding: UTF-8
OS name: "linux" version: "2.6.31-20-generic" arch: "i386" Family: "unix"


安裝完成後即可透過指令建立maven的項目。
一般Java Project建立指令如下:
mvn archetype:create -DgroupId=com.codeline.commons -DartifactId=codelineCommons

Web Project建立指令如下:
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp

groupId指的是此項目的唯一識別,也就是。
artifactId指的是項目的名稱。
archetypeArtifactId指的是項目的Type。

archetypeArtifactId的類型很多,如果不填的話默認是maven-archetype-quickstart,其實Maven2支援另一種的建立項目方式,輸入下列指令:
mvn archetype:generate
Maven會列出所有的archetype並要求輸入其中一種type,信息如下:

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: internal -> appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF)
7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC)
8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2)
9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4)
10: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)
11: internal -> maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
12: internal -> maven-archetype-mojo (A Maven Java plugin development project)
13: internal -> maven-archetype-portlet (A simple portlet application)
14: internal -> maven-archetype-profiles ()
15: internal -> maven-archetype-quickstart ()
16: internal -> maven-archetype-site-simple (A simple site generation project)
17: internal -> maven-archetype-site (A more complex site project)
18: internal -> maven-archetype-webapp (A simple Java web application)
19: internal -> jini-service-archetype (Archetype for Jini service project creation)
20: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)
21: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence) Archetype)
22: internal -> softeu-archetype-jsf (JSF+Facelets Archetype)
23: internal -> jpa-maven-archetype (JPA application)
24: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype)
25: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archetype)
26: internal -> jira-plugin-archetype (Atlassian JIRA plugin archetype)
27: internal -> maven-archetype-har (Hibernate Archive)
28: internal -> maven-archetype-sar (JBoss Service Archive)
29: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)
30: internal -> scala-archetype-simple (A simple scala project)
31: internal -> lift-archetype-blank (A blank/empty liftweb project)
32: internal -> lift-archetype-basic (The basic (liftweb) project)
33: internal -> cocoon-22-archetype-block-plain ([http://cocoon.apache.org/2.2/maven-plugins/])
34: internal -> cocoon-22-archetype-block ([http://cocoon.apache.org/2.2/maven-plugins/])
35: internal -> cocoon-22-archetype-webapp ([http://cocoon.apache.org/2.2/maven-plugins/])
36: internal -> myfaces-archetype-helloworld (A simple archetype using MyFaces)
37: internal -> myfaces-archetype-helloworld-facelets (A simple archetype using MyFaces and facelets)
38: internal -> myfaces-archetype-trinidad (A simple archetype using Myfaces and Trinidad)
39: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create custom JSF components using MyFaces)
40: internal -> gmaven-archetype-basic (Groovy basic archetype)
41: internal -> gmaven-archetype-mojo (Groovy mojo archetype)
Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15: :

在此我選擇18,即是maven-archetype-webapp,Maven又會繼續詢問其他的必要輸入資訊:

[INFO] artifact org.apache.maven.archetypes:maven-archetype-webapp: checking for updates from artifactory
[INFO] artifact org.apache.maven.archetypes:maven-archetype-webapp: checking for updates from central
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar

Define value for groupId: : com.sample.test
Define value for artifactId: : oliversample
Define value for version: 1.0-SNAPSHOT: :
Define value for package: com.sample.test: :
Confirm properties configuration:
groupId: com.sample.test
artifactId: oliversample
version: 1.0-SNAPSHOT
package: com.sample.test
Y: : y

如上所見,按著Maven的問題回答,最後就會建立一個完整的Sample。

[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: maven-archetype-webapp:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.sample.test
[INFO] Parameter: packageName, Value: com.sample.test
[INFO] Parameter: package, Value: com.sample.test
[INFO] Parameter: artifactId, Value: oliversample
[INFO] Parameter: basedir, Value: /home/oliver
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] OldArchetype created in dir: /home/oliver/oliversample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 29 seconds
[INFO] Finished at: Sun Mar 28 21:38:50 CST 2010
[INFO] Final Memory: 10M/107M
[INFO] ------------------------------------------------------------------------


如此一來就會建立一個完整的Maven項目。
利用Maven2建立項目時會有資源庫的概念,如果按照Maven2的預設會在每次建立項目時至Maven2的資源庫下載所需的lib並存放在${user.home}/m2(m2/是隱藏的),但如果要在團隊建立一個共用的資源庫,則可利用代理資源庫的方式,參考了很多代理資源庫,用最多的似乎是Artifactory。

至Artifactory下載Artifactory-2.2.2,Artifactory已經內含jetty了,當然也可整合至Apache裏,可以直接進入Artifactory-2.2.2/bin執行下列指令:
./ artifactory.sh
此時開啓瀏覽器輸入http://localhost:8081/artifactory,若看到下列畫面則表示設定成功。



切換到Artifacts可以發現Artifactory設定了許多的Repository,但總體來說只要在settings.xml的profiles中加入下列的設定:



<profile>
<id>artifactory</id>
<repositories>
<repository>
<id>artifactory</id>
<name>local private artifactory</name>
<url>http://127.0.0.1:8081/artifactory/repo/</url>
</repository>
</repositories>
</profile>

另外再下profiles下方加入啓動profiles的設定即可:

<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>

Ubuntu的Apache安裝

在Ubuntu中安裝Apache很簡單,只需執行下列的指令即可:

sudo apt-get install apache2

要注意是的下列目錄及文件:

/etc/apache2/ #--apache2.conf, httpd.conf
/usr/lib/apache2/modules #--*.so

/etc/init.d/apache2
/usr/sbin/apachectl
/usr/bin/htpasswd

/var/www/ #--webroot

/etc/init.d/apache2及/usr/sbin/apachet1效果是相同的,只是/etc/init.d/apache2會自動執行。

如果有任何的設定需要變更需修改/etc/apache2/httpd.conf。

針對Apache2的啓動與停止命令如下:

/etc/init.d/apache2 start
/etc/init.d/apache2 stop
/etc/init.d/apache2 restart

如果不清楚Apache2命令則直接輸入

/etc/init.d/apache2
* Usage: /etc/init.d/apache2 {start|stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}

2010年3月27日 星期六

GRUB開機管理程式清單的修改

在Ubuntu 9.10的開機管理程式用的是GRUB2,所以已經不再使用原本的menu.lst修改了。
GRUB2的目錄在/boot/grub,GRUB2若要修改開機選項清單必須修改grub.cfg,但是grub.cfg預設是唯讀文件,連root都無法修改,所以必須先修改crub.cfg的文件性質,命令如下:

sudo chmod +w /boot/grub/grub.cfg
  或是
sudo chown a=wr /boot/grub/grub.cfg
  然後才能修改crub.cfg
sudo gedit /boot/grub/grub.cfg

參考文件

Ubuntu目錄結構


/ 根目錄

├boot/ 放置Linux核心與啓動相關文件,目錄下的VMLIUZ-xxx就核心文件。
│ └grub/ GRUB相關文件,現已升級為GRUB2,如欲修改開機清單需修改grub.cfg 。

├dev/ 存放與設備有關文件。
├proc/ 存放系統核心與執行程序資訊,啓動時自動載入記憶體,故不佔用硬碟空間。

├mnt/ 默認掛載點。
├media/ 默認多媒體設備。

├root/ root用的的$HOME目錄。
├home/
│ ├user/ 普通用戶的$HOME目錄。
│ └.../

├bin/ 專門存放所有用戶執行Application的指令,有時此目錄會與usr/bin相同。
├sbin/ 存放系統管理員常用的程序。
├lib/ 在執行或編譯某些程序時要用到的library都在此目錄。
├etc/ 系統啓動過程需要讀取的設定檔都在此目錄。
│ ├init.d/ 所有服務默認的啓動script。
│ ├network/ 所有的網路環境配置script。
│ ├X11/ 與X WINDOWS有關的配置文件。

├usr/ 存放程序與指令,類似WINDOWS下的Program Files。
│ ├bin/ 專門存放用戶執行Application的命令。
│ ├sbin/ 存放管理員執行Application的命令。
│ ├lib/ 在執行或編譯某些程序時要用到的library都在此目錄。
│ ├share/ 存放Application的資源及文件。
│ ├src/ 放置核心系統源始碼的默認目錄
│ ├local/ Application默認安裝目錄,升級後的執行文件放在/usr/local/bin目錄下。

├var/ 所有服務的登錄文件或錯誤信息文件(var/log)都在此。

├temp/ 存放臨時文件
├lost+found/ 磁盤修復文件


特別注意的目錄
  • /etc 啓動與系統文件所在位置。
  • /etc/init.d/ 存放啓動Ubuntu服務的Script。
  • /etc/rc.local/ 存放啓動Ubuntu後的script,可執行使用者自行加入的系統指令。
  • xxx/bin/,xxx/sbin/ 系統默認執行文件的目錄,Root常用的指令都在此,說明如下:
  • /bin : commands in this dir are all system installed user commands
  • /sbin: commands in this dir are all system installed super user commands
  • /usr/bin: user commands for applications
  • /usr/sbin: super user commands for applications
  • /usr/X11R6/bin : X application user commands
  • /usr/X11R6/sbin: X application super user commands
  • /usr/share/man 放置各類套件說明文檔的地方。
  • /usr/local/man 放置各類套件說明文檔的地方。

2010年1月17日 星期日

Ubuntu中重新啓動iBus

iBus是由對岸同胞針對linux開發的輸入法,ubuntu 9.10也採用了iBus,但在使用時偶而會當掉,所以在網路上查了一下,如果當掉之後可以輸入ibus-daemon -d,就可以重新啓動了。

如果不瞭解ibus的命令列,可輸入ibus-daemon --help。

2010年1月10日 星期日

mount/umount指令

在Windows裏有許多的ISO掛載工具可以使用,在Ubuntu裏的掛載工具卻很少,其實只要利用mount/umount指令即可掛載與卸載。

mount 指令為將周邊裝置掛入的指令,這個指令相當常用,所以了解熟悉是必備知識!

格式:mount -t 檔案系統類型 -o 選項 裝置 掛入點

檔案系統

minix Linux 最早使用的檔案系統
ext2 Linux 目前使用的檔案系統
msdos MS-DOS 的 FAT
vfat Windows 95 的 FAT32
nfs 網路檔案系統
iso9660 光碟格式
ntfs Windows NT 4.0 的檔案系統
hpfs OS/2 的檔案系統
auto 自動偵測


掛載
sudo mount -t iso9660 -o loop xxx.iso /media/cdrom0

卸載
sudo umount /media/cdrom0

2009年12月29日 星期二

Ununtu 12.04安裝JDK6

下載jdk-6u33-linux-x64.bin
變更檔案權限chmod +x  jdk-6u33-linux-x64.bin <--更改檔案權限..+x是可以執行的...
sudo cp jdk-6u33-linux-x64.bin /usr/
./jdk-6u33-linux-x64.bin<--會解壓縮成為jdk1.6.0_33資料夾
sudo update-alternatives --install /usr/bin/java java /usr/jdk1.6.0_33/bin/java 60<--將JDK1.6.0_33設為預設的JAVA
sudo update-alternatives --config java<--若有多個JAVA版本可以在此選擇,若沒有則顯示"There is only one alternatives in link group...."



2009年9月22日 星期二

Ubuntu 安裝 Postgres SQL 8.3

Install PostgreSQL

Install the postgresql-8.3 package from Synaptic or apt-get:

$ sudo apt-get install postgresql-8.3

You might also want to install the pgadmin3 tool to help you manage your database:

$ sudo apt-get install pgadmin3

Reset the password of the postgres user

The default superuser, called ‘postgres’, does not have a password by default. We need to add one:

$ sudo su postgres -c psql template1
template1=# ALTER USER postgres with PASSWORD 'password';
template1=# \q

Where ‘password’ is your password. After this we need to modify the password of the postgres UNIX user:

$ sudo passwd -d postgres
$ sudo su postgres -c passwd

You will be asked for a new password, enter the same password with the one you specify in the ALTER USER statement above.

Allow local users to access the server

The default PostgreSQL installation in Ubuntu requires that a PostgreSQL user must also be a unix user. I don’t like it this since it makes it hard for us to create a new PostgreSQL user. I want a PostgreSQL user to be different than a UNIX user. To do this, we need to change the configuration in the pg_hba.conf file:

$ sudo gedit /etc/postgresql/8.3/main/pg_hba.conf

Replace out the line (comment it out by adding a ‘#’ in front of it):

local all all ident sameuser

With this line:

local all all md5

After that you will need to restart the server:

$ sudo /etc/init.d/postgresql-8.3 restart

Now you’re all set. All you need to do is to create a new user, and a database and start coding.

Some important commands to remember:

  1. Creating a new PostgreSQL user
    $ sudo -u postgres createuser -d -R -P 
  2. Create a new database owned by
    $ sudo -u postgres createdb -O  
  3. Executing an SQL file
    $ psql -f   
  4. Removing a database
    $ dropdb -U  
  5. Removing a PostgreSQL user
    $ sudo -u postgres dropuser 
參考資料 Setup PostgreSQL in Ubuntu

2009年9月21日 星期一

如何在Ubuntu中使用BBS

安裝pc manx

sudo apt-get install pcmanx-gtk2

安裝完成後開啓pcmanx..在網址輸入ptt.cc,即可連上PTT

在Ubuntu 使用各種解壓縮程式....

.tar
打包:tar cvf FileName.tar DirName
解包: tar xvf FileName.tar

.gz
壓縮:gzip FileName
解壓1:gunzip FileName.gz
解壓2:gzip -d FileName.gz

.tar.gz
壓縮:tar zcvf FileName.tar.gz DirName
解壓:tar zxvf FileName.tar.gz

.bz2
壓縮: bzip2 -z FileName
解壓1:bzip2 -d FileName.bz2
解壓2:bunzip2 FileName.bz2

.tar.bz2
壓縮:tar jcvf FileName.tar.bz2 DirName
解壓:tar jxvf FileName.tar.bz2

.bz
壓縮:unkown
解壓1:bzip2 -d FileName.bz
解壓2:bunzip2 FileName.bz

.tar.bz
壓縮:unkown
解壓:tar jxvf FileName.tar.bz

.Z
壓縮:compress FileName
解壓:uncompress FileName.Z

.tar.Z
壓縮:tar Zcvf FileName.tar.Z DirName
解壓:tar Zxvf FileName.tar.Z

.tgz
壓縮:unkown
解壓:tar zxvf FileName.tgz


.tar.tgz
壓縮:tar zcvf FileName.tar.tgz FileName
解壓:tar zxvf FileName.tar.tgz

.zip
壓縮:zip FileName.zip DirName
解壓:unzip FileName.zip

.rar
壓縮:rar e FileName.rar
解壓:rar a FileName.rar

.lha
壓縮:lha -a FileName.lha FileName
解壓:lha -e FileName.lha

安裝RAR
sudo apt-get install rar

Ubuntu下重新启动 SCIM

Ubuntu的預設安裝設定,使用的是scim做為主要的輸入法介面,不過預設的情況下,會啟用一堆不會用到的輸入法,選擇將這些輸入法關閉,scim也不會即時對應這些改變,通常得重新登入。


不過現在有個不必登出的方法,按下Alt + F2(或啟動終端機視窗),輸入
pkill ^scim && scim -d && scim-bridge


就會將運行中的scim相關程式關閉,並重新啟動。

pkill ^scim會終止以scim為名開頭的程式,而scim -d && scim-bridge則會啟動scim。


文章來源:每一天都要進步

2008年11月16日 星期日

在Ubuntu 8.10安裝OpenOffice 3.0繁體中文版

網路上安裝OpenOffice 3.0繁體中文版的教學很多,我參考了很多資料終於安裝成功了,分享如下:

第一步:移除OpenOffice 2.4
請開啓系統->管理->Synaptic套件管理程式,將有關於OpenOffice的套件都徹底移除!

第二步:安裝OpenOffice 3.0英文版
開啓系統->管理->軟體來源

開啓第三方軟體Tab,點選加入按鈕,輸入deb http://ppa.launchpad.net/openoffice-pkgs/ubuntu intrepid main
點選關閉,然後按重新載入,等待視窗關閉,這時螢幕右上角會有更新通知,全部更新!


第三步:安裝OpenOffice 3.0繁體中文版

請到http://ftp5.gwdg.de/pub/openoffice/extended/3.0.0rc4/下載OOo_3.0.0rc4_20080930_LinuxIntel_install_zh-TW_deb.tar.gz檔案,請注意如果您的Ubuntu還沒裝JRE,請下載OOo_3.0.0rc4_20080930_LinuxIntel_install_wJRE_zh-TW.tar.gz檔案

下載完成後請解開檔案,進入DEBS資料夾,在終端機視窗輸入sudo dpkg -i *.deb,OpenOffice 3.0就安裝完成了!
如果沒有辦法在功能列看到OpenOffice的清單,則執行DEBS/desktop-integration/,執行openoffice.org3.0-debian-menus_3.0-9354_all.deb檔案後,功能列就會有OpenOffice的清單了!!

2008年10月31日 星期五

在Ubuntu文字模式顯示中文字

Ununtu中文版會有許多中文資料及中文訊息,但在文字模式是亂碼!
要解決這個問題就是安裝 zhcon囉~

在Ununtu安裝zhcon非常方便!

1.在文字模式或終端機輸入下面指令

$ sudo apt-get install zhcon
 Ubuntu會自動下載zhcon及相關套件!

2.完成安裝後其實在文字模式輸入下面指令就可以顯示中文了
$ zhcon --utf8 --drv=vga
 
但其實有幾個地方可以稍做修改!

1.其實zhcon的中文編碼是預設是gbk,若想改變,打開/etc/zhcon.conf,找到下面這一行

defaultencode = gb2312
將gb2312改成big5存檔,這樣一來就會是big5的編碼了!
zhocn.conf裏還有許多細部設定可改,例如修改游標大小等,在這就不說明了!

2.另外如果嫌每次都要在文字模式輸入zhcon --utf8 --drv=vga太麻煩了,可開啓/etc/bash.bashrc檔案,並在最後一行加入下列的alias並存檔。

alias zhcon='sudo zhcon --utf8 --drv=vga'
再執行bash從新載入bash,這樣一來以後只要輸入zhcon即可。


zhcon官方網站
zhcon簡體中文官方網站