2012年6月1日 星期五

import 自簽憑証到 JDK 中

  • 先找出jdk 存放憑証的地方,預設目錄為%JAVA_HOME%/jre/lib/security 底下的 cacerts 檔
  • 準備好 要匯入的檔案  例:/tmp/newcert.der
  • 工作目錄換到  %JAVA_HOME%/jre/lib/security
  • keytool -importcert -file /tmp/newcert.der -keystore cacerts -alias openssl_crt_der

2012年5月29日 星期二

command line svn ignore 設定

  • svn propget svn:ignore [路徑] →用來看[路徑]下的svn:ignore清單
      例:
    1. svn propget svn:ignore . → 看當前目錄的 ignore 設定
    2. svn propget svn:ignore folderA/borderAA → 看folderA/borderAA目錄下的 ignore 設定
    所以概念上,svn:ignore 是依每個目錄去讀取(設定)的。
  • svn propset svn:ignore [路徑] [ignore檔案名 或 pattern名]→用來設定[路徑]下的svn:ignore清單。
    一旦執行之後原本的ignore清單就會被overwrite掉,基本上個人不建議這種做法,因為沒有先看過 原本的設定是什麼的話,直接下指執令,裡svn:ignore設定會直接被清掉。就算看過了,你要把原本的設定重新打一次,再加上要新增的ignore。感覺蠻麻煩的。
  • $svn propedit svn:ignore [路徑]
    會用文字編輯器去編輯 svn:ignore但是如果subversion沒有設定預設的文字編輯器時,可以加上 --editor-cmd [編輯器] 來指定
      例:
    • $svn propedit svn:ignore . --editor-cmd vim , 表示指定用vim 來做為編輯器,編輯當前目錄的 svn:ignore。
    如果想要當前目錄下有個資料夾名稱是 folderA ,裡面有個檔案叫 ooxx.xml 想要把它ignore時。
    作法為
    1. 在當前目錄下 $svn propedit svn:ignore folderA --editor-cmd vim 進入編輯
      加上ooxx.xml 在文字檔內
    2. $cd folderA
      $svn propedit svn:ignore . --editor-cmd vim 進入編輯
      加上ooxx.xml 在文字檔內
    3. 但是不能在當前目錄下 $svn propedit svn:ignore . --editor-cmd vim 進入編輯
      然後加上 folderA/ooxx.xml 這樣是不會有ignore 的效果的

2012年4月30日 星期一

在 ubuntu 12.04 下自行安裝 subversion 1.7

在ubuntu 12.04 下 用apt-get 目前安裝的版本為1.6 想要自行安裝 1.7 過程如下:
  • 到 subversion 的官方網站下載目前 release 的最新版本: 下載的檔案為 subversion-1.7.4.tar.gz
  • 自行安裝要下 ./configure 時,遇到 錯誤訊息:說是沒有安裝APR (Apache Portable Runtime (APR))雖然不知道這什麼,但總之是安裝過程不可缺的。於是去下載
    Unix Source: apr-1.4.6.tar.gz和
    Unix Source: apr-util-1.4.1.tar.gz 回來 分別解開來,安裝 (./configure , make , make install)
    遇到要輸入 --with-apr 時,就加上參數 --with-apr=/usr/local/apr 遇到要輸入 --with-apr-util 時,就加上參數 --with-apr-util=/usr/local/par/bin
  • 又遇到錯誤訊息,說必需要有 sqllite ,下載sqlite-autoconf-3071100.tar.gz 版本,一樣 安裝(./configure, make , sudo make install)
  • error: subversion requires zlib →
    下載 zlib-1.2.6.tar.gz
    tar -xvzf zlib-1.2.5.tar.gz
    cd zlib-1.2.5
    (make, sudo make install)
  • 依上述方法安裝後,重新下 subversion 的指令:
    ./configure --prefix=/usr/local/zlib
    ./configure --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr/bin --with-zlib=/usr/local/zlib
    出現,警告訊息: configure: WARNING: we have configured without BDB filesystem support
    ......
    You don't seem to have Berkeley DB version 4.0.14 or newer
    ......
    再去 下載 Download Berkeley DB 5.3.15 for Linux : db-5.3.15.tar.gz
    安裝後 subversion 的 ./configure 終於過了
  • 最後就是手動安裝subversion

2012年4月24日 星期二

ubuntu 亮度 調整 Acer 8481

最近手邊有一台 Acer 8481 裝好 ubuntu 10.10 後一開機覺得亮度太亮, 系統調整亮度的功能似呼都沒有作用,於是google 一下,發現這篇:Ubuntu 10.10 brightness problem in Acer Aspire 4741 照它所提供的做法:
  1. sudo vi /etc/default/grub (自己習慣用vi)
  2. 把 GRUB_CMDLINE_LINUX="" 改成 GRUB_CMDLINE_LINUX="acpi_osi=Linux"
  3. sudo update-grub
  4. 重開機
重開機後,我用 Fn + ← → 就可以調整亮度了

2012年4月16日 星期一

X蝦米 on Ubuntu 10.10 ibus 123

下載現成做好的檔:Boshiamy for iBus
我自己是選 ibus-table-boshiamy_1.3.0.20101012-1_all.deb

不知道為什麼,double click ubuntu 軟體中心回應我錯誤不能裝,只好自己打開.deb
將 /tables/boshiamy.db 複製到 /usr/share/ibus-table/tables/
將/icons/boshiamy.png 複製到/usr/share/ibus-table/icons/
restat 輸入法。 搞定!



參考文章:

2012年3月21日 星期三

entity converter Value is not a valid 問題

問題描述:

在一個查詢頁,有 select 、button ,
select 項目用 做 view 和 controller 的值轉換。
範例如下:



但是在網頁很久沒有動作後,再去改變下拉選單的內容,會出現 Value is not a valid 錯誤訊息。

參考網路上說明後,推測是因為 過很久再去點選畫面時,view 經由entity converter 傳成的物件和 emtityManager 重新 query 的list 在比較時,發現沒有符合。所以認為選擇的值是 Value is not a valid 。

解決方法:overwrite equals 方法。 真是夠簡單的。

The scenario

JSF runs the converter and loads the entity from the persistence context; JSF runs any validators, and adds it's own - that the selected object must be in the original list; the validation fails as a new object has been loaded from the persistence context.

The solution

You've got two options:

Ensure that you are in a long-running conversation that spans the both the select list creation and the submission of the form.
Use key equality rather than object equality (make equals return true if both objects have the same natural or business key). It's important to note that basing equality on surrogate key identity isn't recommended. You can read more here
Which approach should you take? The second solution is the simplest to understand but sometimes it is hard (or not possible) to define a natural key so you'll need to use the first solution.
參考來源

2011年6月11日 星期六

spring IoC 使用factoryBean

最近才開使接觸spring IoC ,一般在XML 中設定 的 property 都是使用
......
<bean id="someBean" class="xxx.ooo.ClassName">
 "property name="someField" ref="anotherObject">  
</bean>
......
時都是指定到另一個bean 的,做為參考。換言之一定會存在著
......
<bean id="anotherObject" class="xx.oo.ClassName2">
  ......
</bean>
......

但有時候需要的是用factory的方式產生出來才塞給像上述的 someField的話要怎麼做呢?
上網路上查詢,發現有三個方式。 我自行理解後,筆記如下:
1.用static method 產生物件
2.用一般method產生物件
3.用透過 實作 FactoryBean interface

方法1說明:
以上述的例子來說,假設我們要注入xxx.ooo.ClassName 類別的 someField 欄位,原本是指到anotherObject 這個bean;現在有另一個類別提供一個static method 會產生出someField 需要的物件。

public class StaticFactoryBeanTest {

 public static SomeFieldClass createObject()
 {
               ......
       return someFieldInstance;
 }
}

在XML 中的使用方式為:
<bean id="xx" class="oo.xx.StaticFactoryBeanTest" factory-method="createObject" />


這時候,bean xx 指的就不是 oo.xx.StaticFactoryBeanTest的物件而是 它的static method :createObject 所產生的物件,注意在XML 中要這樣使用,此方法必需為static method

方法2說明:
在XML 中使用方式為:
<bean id="instanceFactoryBean" class="oo.xx.InstanceFactoryBean">
......
</bean>
<bean id="product" factory-bean="instanceFactoryBean" factory-method="createProduct" />
instanceFactoryBean 是一般的bean ,它的類別是oo.xx.InstanceFactoryBean
但 product 它是靠 instanceFactoryBean 的 createProduct 方法產生的物件,所以它的class不是oo.xx.InstanceFactoryBean,而是看createProduct 產生了什麼。

方法3說明:
在XML 中使用方式為:
<bean id="product" class="oo.xx.MyFactoryBean" />
oo.xx.MyFactoryBean 是implements org.springframework.beans.factory.FactoryBean 這個interface
而FactoryBean 有三個method 分別是:
public Object getObject();
public Class getObjectType();
public boolean isSingleton();

而這個product 注入的是 oo.xx.MyFactoryBean 的getObject()方法產生的物件,並非是oo.xx.MyFactoryBean這個類別的instance

2011年6月3日 星期五

spring 使用 application 中定義的 properties

問題:
在applicationContext 中常會設定一個properties 來載入一些設定檔
通常是
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
.....
</bean>

但發現 這個 PropertyPlaceholderConfigurer 類別不提供它的 java.util.Properties 讓我們用。
但是它的父類別org.springframework.core.io.support.PropertiesLoaderSupport 有提供一個protected method
protected Properties mergeProperties() throws IOException

所以這邊提供一種做法是,自己寫一個Class 繼承 PropertiesLoaderSupport ,然後裡面提供一個method

public class MyPropertyPlaceholderConfigurer extends
  PropertyPlaceholderConfigurer {

  Properties mergedProperties;

   public Properties getMergedProperties() throws IOException {
     if (mergedProperties == null) {

       mergedProperties = mergeProperties();

     }
     return mergedProperties;

   }
}

然後 applicationContext 裡的 propertyConfigurer設定改成
<bean id="propertyConfigurer" class="MyPropertyPlaceholderConfigurer">

......
這樣就可以在之後使用這個bean 取得 properties

由Spring 取得 Jboss JNDI datasource

問題:非一般由web container 取得JDNI 的方式。而是一隻獨立程式需要存取DB,要從JBoss取得JNDI datasource 。
解決方式:

在 applicationContext中
原本會有


...
 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource" ref="jdbcDataSource"/>
</bean>
<bean id="jdbcDataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
...>
...
這是使用jdbc的方式連的

加上
<bean id="jndidataSource"  class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="your_JNDI_name"/>
<property name="resourceRef" value="false"/>
<property name="jndiTemplate" ref="jndiTemplate" />
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">jnp://your_JBoss_IP:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
<prop key="jnp.disableDiscovery">true</prop>
</props>
</property>


然後在執行這隻獨立的jar 檔時,加上jboss 的jar 檔到 classpath中

for example:
java  -cp /...[jboss home].../jboss-as/client/jbossall-client.jar:yourJarFile.jar your.main.class
不過這個方式要JDNI,好久啊~久到爆炸,在自己的localhost 跑都要超過兩分鐘 orz

Cron Job 出現亂碼問題

問題: java file 丟到 linux 下執行有遇到io處理都好好的。但同一隻程式用 cron job 跑,有io 的部份就出現亂碼。

解決方法:
example.sh 範例
LC_ALL=zh_TW.UTF-8
LANG=zh_TW.UTF-8
/....[java path]..../java -Dfile.encoding=UTF-8 -jar yourJava.jar


這樣就能解決IO出現亂碼的問題了。

2011年5月11日 星期三

sybase SQL 取得當週星期一(get Monday)

背景說明:要取得當周第一天。(通常系統都是把星期天設為當週第一天)所以一般來說,只要呼叫一個 類似  weekday 之類的函數得出目前是 當周的第 n 天,然後把目前日減掉 n即可。

問題: 以星期一做為一周的第一天。帶入日期取得當週第一天。
原本將日期帶入 weekday 的函數得到的 數字  1~7 直接減的話,得到的日期是星期天。

2011年5月10日 星期二

jQuery UI datepicker 1.8.12 日期輸入限制

jQuery UI datepicker 很方便的讓一個input element 可以有calendar做為協助輸入的ui,不過有時候,要validate 輸入的日期資料時,理想的方式之一就是不要讓不想輸入的資料出現。
舉例來說,如果只想讓使用者輸入 星期一 的日期,其它的日期都不要出現的話。該怎麼做?

jQuery UI datepicker 1.8.12 顯示問題

jQuery datepicker 1.8.12 使用發現一個問題 就是 z-index 每次都會被自動設成 1,如果畫面上有 z-index 大於1的,就有可能被蓋住。

解決方法:一種是設一個很大的數字,另一方式,就是找出目前頁面中z-index 最大的element 然後再設比它大一點。
看起來後者是比較完善的解決方法。要做到此點,請參考下列步驟:

2011年5月1日 星期日

sybase 取得月天數

如何使用SQL ,代入日期,取得當月天數? 例: 傳入 1/23  return 31,傳入  2/10 return 28(潤年29)

javascript 取得 月天數

function daysInMonth(iMonth, iYear)
{
    return 32 - new Date(iYear, iMonth, 32).getDate();
}

iMonth:0~11
iYear:西元年 yyyy

原理說明:
new Date(iYear, iMonth, 32) ,會依 年月日,產生一個日期,但是日期超過該月的部份會使產生的日期變成下個月的日期
舉例:
new Date(2011, 0, 32) ,是指要產生一個日期是 2011年1月32號的,但是因為1月只有31天,所以產生出來的時間變成是2011年2月1號,也就是自動幫你進位了。
產生出來的日期再用 .getDate()取得 "日" 的部份,最後用 32 去減。 換句話說,用32代入產生的日期不管是代到哪個月都會進位,進位後的日數,可能是1 ~ 4 不等,也就是說原本的月份日數是比32 少 1~4不等。 所以用32減去,就是所求。

變通一下,把function 內的兩個32 改成是 35或是其它 >31 但 <60 的數也是可以,只要不要讓它再次進位到下個月執行的意義和原做法就是一樣的。

參考:http://snippets.dzone.com/posts/show/2099

2010年11月24日 星期三

Jboss5.0.1 + php (5.1.6)

為了使用 Jboss5.0.1 + php (5.1.6)共同運行。

作業系統: windows XP

1.下載 JBoss 5.0.1 GA,下載回來檔名為:jboss-5.1.0.GA.zip

2.下載 php module

2010年11月23日 星期二

test script


sdfadsfasdf
xvcsdfas
asdfasd
zxcvzxcv
bhbbbb



2009年6月18日 星期四

MySQL migration tool

使用 MySQL migration tool 時發生問題: ERROR: Could not load java class com/mysql/grt/Grt. Error initializing Java module loader (10009). Please check the .\java and .\java\lib directories. 以為是classpath 或是 path設定有問題。 上網查之後,發現是因為系統中有JDK1.5 以前的版本就會造成這個錯誤。 自己後來是把JDK 1.4從系統移除掉,之後就解決這個問題了。 網路上有人提供另一方法是將 HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime 低於1.5的版本移掉就行。 不過這個方法我沒試過。