2012年4月2日 星期一

[Linux] JDK,JRE and open jdk,sun jdk差別

JDK跟JRE的差別:
JDK和SDK其實我們通常指的都是同一個東西, 而JDK與JRE的差別是,JDK可以拿來編譯,你所寫的Java程式, 如果你想要學Java, 就請裝JDK.如果只是要執行Java的程式, 你只要裝JRE就可以了. (JRE是JDK的子集)

JDK版本介紹:
JDK(Java Development Kit)就是Java的開發工具包,是給Java開發者使用,所以以照自己的需求來安裝套件。
Java SE=Java Standard Edition (主要用於桌面程序,控制台開發)
Java EE=Java Enterprise Edition (企業級開發)
Java ME=Java Mobile Edition (嵌入式開發)

在大多數的Linux發行版裡面,幾乎都會內建OpenJDK這套JDK.
什麼是OpenJDK?
這裡就簡述一下其歷史:
OpenJDK簡單來說就是JDK7的開放原始碼版本。
你可以從 http://openjdk.java.net/projects/jdk6/ 很清楚的看到,自從JDK7 b10以後,就產生了一個新計畫 OpenJDK ,它是一個開放原始碼計畫,以 GPL釋出。OpenJDK已經成為了JDK7的主幹開發,而Sun JDK7則是基於OpenJDK7的原始碼所發布的,其大部分原始碼都相同,只有少部份原始碼被取代掉,使用JRL(非自由軟體的開放原始碼)釋出。

那麼OpenJDK6呢?很多人都認為它就是JDK6的分支,那你就錯了,實際上JDK6還是屬於JRL釋出,且與OpenJDK6有很大的差異,OpenJDK6僅是一個OpenJDK7的分支,並且去除Java SE 7的特性,盡量使其符合Java SE 6。

以下說明Sun JDK(以後可能要叫做Oracle JDK)與OpenJDK的不同:

釋出授權條款的不同:
OpenJDK 採用GPLv2 釋出而 Sun JDK則採用 JRL釋出。兩者協議雖然都是開放原始碼的,但在使用上卻有很大的不同,其中最大的便是,GPLv2允許在商業上面使用,而JRL僅允許個人研究使用。OpenJDK並不包含Deployment(部署)功能:部署的功能包含:Browser Plugin、Java Web Start、以及Java控制面板。這些功能在OpenJDK中找不到。然而Icedtea計畫自行開發了一個Plugin與整合了 netx 這個 Java Web Start 計畫,使得OpenJDK也可以體會到部份部署的功能。

原始碼尚未完整:
OpenJDK大致上與Sun JDK原始碼相符合,然而部份原始碼因為產權問題無法開放給 OpenJDK使用,其中最主要的部份就是JMX中的可選元件SNMP部份的程式碼。因此這些不能開放的原始碼將它作成plug,以供OpenJDK編譯時使用,你也可以選擇不要使用plug。而Icedtea則為這些不完整的部份開發了相同功能的程式碼(僅有OpenJDK6),促使OpenJDK更加完整。

部份程式碼以開放原始碼專案替代:
OpenJDK由於產權問題,剝離了很多產權非Sun的程式碼。為了補足這些程式碼,因此使用了許多功能一樣的開放原始碼專案。最明顯的例子就是:字體柵格化引擎,使用FreeType替代。

只包含最精簡的JDK:
OpenJDK不包含其他軟體包,如:Rhino、Java DB(Apache Derby)、JAXP(僅提供原始碼下載網址)...... 且可以分離的軟體包也盡量的分離。然而這些計畫大多數也是自由軟體,你可以自行下載並且加入。在Icedtea裡面,也重新加入了這些軟體包,因此你使用Icedtea編譯OpenJDK時,它可能會要求你安裝或指定Rhino位置。

不能使用Java商標:
由於OpenJDK並不完整,因此不是標準的Java,也就無法使用Java商標。但是Icedtea則致力於補完OpenJDK的不完整,至今已經大致上補完了,也可通過JCK認證,因此若使用Icedtea補丁的OpenJDK,你輸入 "java -version" 就可以看到最前面顯示的是 "Java" 而不是 "OpenJDK" 。基本上,在 Sun Java 體系中,Java SE 這部份開放原始碼還不夠徹底,而 JavaFX 則是僅開放 Compiler 的原始碼(註解1),其中的理由部份是產權問題。此外,也希望Oracle能讓JCP更自由一點,讓廠商們有公平發表機會,並且開放其JCK與TCKs工具。一旦開放之後,相信Java發展將會更加迅速,每個人都有提供意見的管道,並使Java能夠更普及,甚至在動態網頁上,Java Applet能夠重回原本被 Flash取代的地位。

註解1:你會發現你沒有安裝JavaFX,卻可以執行JavaFX的程式。實際上你正要執行JavaFX程式時,網頁會提供一個JavaFX的下載地點,一旦你瀏覽到含有JavaFX的網站,就會自動去JavaFX官方網站下載JavaFX執行環境來執行。

2012年3月21日 星期三

[Linux] 強制設定x window解析度

OS: ubuntu 11.04版
HW: disktop VIA VX900 內建顯卡
在x window裡因為讀不到顯示器的EDID,所以需要強制設定輸出解析度
How change display resolution settings using xrandr
1.查詢預設定解析度的內容
nash@ubuntu:/$ cvt 1920 1080 57
# 1920x768 56.9 Hz (CVT) hsync: 63.67 kHz; pclk: 163.0 MHz
Modeline "1920x1080_57.00" 163.00 1920 2042 2240 2560 1080 1083 1088 1119 -hsync +vsync
2.加入新的解析度到linux中
nash@ubuntu:/$ xrandr --newmode "1920x1080_57.00" 163.00 1920 2042 2240 2560 1080 1083 1088 1119 -hsync +vsync
3.查詢顯示器名稱
nash@ubuntu:/$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maxumum 4096 x 4096
VGA-1 connected 1920x1080+0+0(normal left inverted right x axis y axis)0mm x 0mm
1360x768 59.8
1024x768 60 * #表示目前使用中的解析度
800x600  60.3    56.2
848x480  60
640x480  59.6    59.9
4.加入預設定解析度到linux中
nash@ubuntu:/$ xrandr --addmode VGA-1 1920x1080_57.00
5.查詢解析度是否加入
nash@ubuntu:/$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maxumum 4096 x 4096
VGA-1 connected 1920x1080+0+0(normal left inverted right x axis y axis)0mm x 0mm
1360x768 59.8
1024x768 60 * #表示目前使用中的解析度
800x600  60.3    56.2
848x480  60
640x480  59.6    59.9
1920x1080_57.00  57.0 #新增的解析度
6.輸出
建議用x window裡面system->Preferences->Monitors去設定新增的解析度,因為如果新增解析度不支援他在30秒後會回復到原本的設定解析度,不會一直卡在黑畫面,然後要重開機進到single去修改
如果有支援可用command line設定輸出

nash@ubuntu:/$ xrandr --output VGA-1 --mode 1920x1080_57.00 #此時畫面解析度就會變化了
7.以上設定均為暫時性所以需要寫到開機時執行以求每次開機都會設定此解析度
nash@ubuntu:/$ gksudo gedit /etc/gdm/Init/Default
..........
..........
PATH=/usr/bin:$PAT  #找到此兩行把指令加入到他下面即可
OLD_IFS=$IFS
xrandr --newmode "1920x1080_57.00" 163.00 1920 2042 2240 2560 1080 1083 1088 1119 -hsync +vsync
xrandr --addmode VGA-1 1920x1080_57.00
xrandr --output VGA-1 --mode 1920x1080_57.00
8.重新開機檢查是否成功

參考資料:
http://www.ubuntugeek.com/how-change-display-resolution-settings-using-xrandr.html
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=34432&forum=3&post_id=159036#forumpost159036
https://wiki.ubuntu.com/X/Config/Resolution
http://shanereustle.com/blog/force-screen-resolutions-on-ubuntu.html


2012年3月19日 星期一

[Linux] mplayer play video in text mode(console)

OS: ubuntu 11.04
HW: VIA VX900
1.安裝mplayer
nash@ubuntu:/$ sudo apt-get install mplayer*  
2.安裝mplayer framebuffer套件
nash@ubuntu:/$ sudo apt-get install xine*  
3.檢查自身電腦的能力到哪
    一:下載軟體
nash@ubuntu:/$ sudo apt-get install hwinfo  
   二:下command查看
nash@ubuntu:/$ sudo hwinfo --framebuffer | grep Mode  
 可以看到list可支援的解析度有幾種


接下來就是下command來播播看
nash@ubuntu:/$ sudo mplayer -vo fbdev -vf scale=1280:1024 aaa.avi  
or
nash@ubuntu:/$ sudo mplayer -vo fbdev -zoom -x 1280 -y 1024 aaa.avi  
    


參考資料:
http://jamyy.dyndns.org/blog/2008/12/419.html
http://keykusosrw.blogspot.com/2011/08/framebuffer-console-2011-1.html
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=89685
http://ubuntu543.blogspot.com/2010/08/blog-post.html
https://wiki.ubuntu.com/FrameBuffer
http://www.tldp.org/HOWTO/Framebuffer-HOWTO/index.html
http://ubuntuforums.org/archive/index.php/t-258484.html
http://wiki.robotz.com/index.php/Framebuffer_Console

2012年3月16日 星期五

[Linux] ubuntu 11.04 autologin text mode

ubuntu 11.04
一:開機自動login到文字模式                    
1.修改/etc/defautle/grub
nash@ubuntu:/$ sudo vi /etc/default/grub 

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX_DEFAULT="quiet text"
GRUB_CMDLINE_LINUX=""
..........
..........
..........
更新
nash@ubuntu:/$ sudo update-grub

2.下載mingetty,and修改tty1.conf
nash@ubuntu:/$ sudo apt-get install mingetty
nash@ubuntu:/$ sudo vi /etc/init/tty1.conf
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system  is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 tty1
exec /sbin/mingetty --autologin username tty1 #username=自己的帳號

3.重開機
nash@ubuntu:/$ sudo reboot

二:取消sudo密碼
nash@ubuntu:/$ sudo vi /etc/sudoers

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
USERNAME ALL=(ALL) NOPASSWD: ALL
#includedir /etc/sudoers.d


參考文章:
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?viewmode=compact&topic_id=43964&forum=22
http://www.gnu.org/software/grub/manual/grub.html
http://ecken-tw.blogspot.com/2009/12/ubuntu-910-desktop-console-mode.html
http://www.linuxquestions.org/questions/linux-desktop-74/%5Bubuntu-10-04%5D-root-auto-login-to-console-mode-806030/
http://chiahu.com/blog/?p=456

2012年3月15日 星期四

[Linux] CentOS Disable power button in text mode

原因: 當按下power key後系統會自動關機
目的: 取消這個功能
OS: CentOS 6.2
1.先檢查BIOS中的電源管理item是否有Soft-Off by PWR-BTTN選項
    Soft-Off by PWR-BTTN < Instant-Off >
2.在/etc/acpi/events/ 中把powerbtn.conf裡的action mark就可以了

[root@localhost /]# vi /etc/acpi/events/powerbtn.conf
event=button/power.*
#action=.....
參考:http://www.centos.org/docs/5/html/5.1/Cluster_Administration/s2-bios-setting-CA.html
         http://bluequiet.blogspot.com/2009/05/linuxacpid.html

2012年3月14日 星期三

[Linux] how to login centos 6 text mode by user

記錄一下
在centos 6.2裡開機自動login user in text mode

for text based autologin in RHEL6, edit /etc/init/tty.conf

[user@localhost /]# sudo vi /etc/init/tty.conf
# tty  - getty 
#
# This service starts the configured number of gettys.


stop on RUNLEVEL=[S016]

respawn
instance $TTY
#exec /sbin/mingeety $TTY
exec /sbin/mingetty --autologin username $TTY //改成這樣


參考: http://sudhaker.com/23/centos-rhel-6-autologin

2012年3月12日 星期一

[Linux] read / write serial port

這幾天在CentOS 6.2裡練習寫 USB轉serial port功能記錄一下以免以後忘記


#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

int fd;
#define DEVICE "/dev/ttyUSB0"

int writeport(int fd, unsigned char *chars, int numBytes)
{
//show array contents
//printf("write array contents:\n");
int counter = 0;
printf("write array = ");
while(counter < numBytes)
{
printf("%x,", chars[counter]);
counter++;
}
printf("\n");

int n = write(fd, chars, numBytes);
if (n < 0) {
fputs("write failed!\n", stderr);
return 0;
}
//all good
return 1;
}

int readport(int fd, unsigned char *result)
{
int iIn = read(fd, result, 254); //13); //254);

//show result array
int counter = 0;
printf("read array = ");
while(counter < iIn)
{
printf("%x,",result[counter]);
counter++;
}
printf("\n");

if (iIn < 0) {
if (errno == EAGAIN) {
printf("SERIAL EAGAIN ERROR\n");
return 0;
} else {
printf("SERIAL read error %d %s\n", errno, strerror(errno));
return 0;
}
}
return 1;
}

int getbaud(int fd)
{
struct termios termAttr;
int inputSpeed = -1;
speed_t baudRate;
tcgetattr(fd, &termAttr);
/* Get the input speed.                              */
baudRate = cfgetispeed(&termAttr);
switch (baudRate) {
case B0:      inputSpeed = 0; break;
case B50:     inputSpeed = 50; break;
case B110:    inputSpeed = 110; break;
case B134:    inputSpeed = 134; break;
case B150:    inputSpeed = 150; break;
case B200:    inputSpeed = 200; break;
case B300:    inputSpeed = 300; break;
case B600:    inputSpeed = 600; break;
case B1200:   inputSpeed = 1200; break;
case B1800:   inputSpeed = 1800; break;
case B2400:   inputSpeed = 2400; break;
case B4800:   inputSpeed = 4800; break;
case B9600:   inputSpeed = 9600; break;
case B19200:  inputSpeed = 19200; break;
case B38400:  inputSpeed = 38400; break;
case B115200:  inputSpeed = 115200; break;
}
return inputSpeed;
}

int initport(int fd)
{
struct termios options;
// Get the current options for the port...
tcgetattr(fd, &options);

// Set the baud rates to 115200...
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);

// Enable the receiver and set local mode...
options.c_cflag |= (CLOCAL | CREAD);

//disable hardware flow control
options.c_cflag &= ~CRTSCTS;

//disable software flow control
options.c_iflag &= ~(IXON | IXOFF | IXANY);

//raw input
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

//raw output
options.c_oflag &= ~OPOST;

//No parity - 8N1
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;

// Set the new options for the port...
tcsetattr(fd, TCSANOW, &options);

return 1;
}

int main(void)
{
unsigned char command[7];
unsigned char sResult[7];

printf("Start open port...\n");
fd = open(DEVICE, O_RDWR);
//fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
return 1;
}
else
{
fcntl(fd, F_SETFL, 0);
}

initport(fd);
printf("baud=%d\n", getbaud(fd));

command[0]=0xC0;
command[1]=0x73;
command[2]=0x07;
command[3]=0x0A;
command[4]=0x00;
command[5]=0x00;
command[6]=0xBE;

if (!writeport(fd, command, 7))
{
printf("write failed\n");
close(fd);
return 1;
}

sleep(2);

fcntl(fd, F_SETFL, 0);    

if (!readport(fd,sResult))
{
printf("read failed\n");
close(fd);
return 1;
}

close(fd);
return 0;
}

參考網站: http://forums.devx.com/showthread.php?t=170839