2008年9月7日 星期日

Read environment variables in Java

_log.info("TEMP : " + System.getProperty("java.io.tmpdir"));
_log.info("PATH : " + System.getProperty("java.library.path"));
_log.info("CLASSPATH : " + System.getProperty("java.class.path"));
_log.info("SYSTEM DIR : " + System.getProperty("user.home"));
_log.info("CURRENT DIR: " + System.getProperty("user.dir"));

http://www.rgagnon.com/javadetails/java-0150.html

2008年8月20日 星期三

GP materials

1. GP - how to implement Service Level of Agreement in GP

https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5929

2. Cross-application alerts in processes: An example based on Guided
Procedures

https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/9119

3. Guided Procedures Explorations: Process Runtime Dashboard

https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6271

4. How To Create Dynamic Approval Process Using Conditional Loop Block
in Guided Procedure

https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6664

5. A Tale of Two Brothers: Guided Procedures and the SAP NetWeaver BPM
Product

https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/10050

2008年8月10日 星期日

在WinXP開機、關機時自動執行指令碼

1.先從開始 » 執行... 輸入 gpedit.msc 然後按下 Enter,開啟群組原則。
2.然後找到本機電腦 原則 » 電腦設定 » Windows 設定 » 指令碼 - (啟動/關機)
3.在啟動及關機處,新增指令碼名稱及指令碼參數

2008年7月8日 星期二

Weblogic 10 ANTLR issue

Due to the issue of ANTLR that weblogic 10 uses internally, we need to add a file WEB-INF/weblogic.xml with the following contents to solve the conflict:


<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
                    http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">

   <container-descriptor>
      <prefer-web-inf-classes>true</prefer-web-inf-classes>
   </container-descriptor>
</weblogic-web-app>


This file make Weblogic use classes and libraries in the web application before other libraries in the classpath.

2008年7月7日 星期一

Struts Download File Example

public ActionForward doViewAttachFile(ActionMapping aMapping, ActionForm aForm,
HttpServletRequest aRequest, HttpServletResponse aResponse) throws Exception {
Efp136Form efp136Form = (Efp136Form) aForm;
Efp136m efp136m = (Efp136m) efp136Form.getEntity();

String fileName = URLEncoder.encode(efp136m.getAttachFileName(), "UTF-8");
aResponse.setHeader("Content-disposition", "attachment; filename=" + fileName);
aResponse.setContentType(efp136m.getAttachFileType());
aResponse.setContentLength(efp136m.getAttachFileSize().intValue());

ServletOutputStream servletOutputStream = aResponse.getOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(efp136m.getAttachFileData());
BufferedInputStream bufferedInputStream = new BufferedInputStream(byteArrayInputStream);
byte[] bytes = new byte[2048];
while (bufferedInputStream.read(bytes) != -1) {
bufferedOutputStream.write(bytes);
}

servletOutputStream.flush();
byteArrayInputStream.close();
servletOutputStream.close();
return aMapping.findForward(VIEW_ATTACH_FILE_SUCCESS);
}

2008年7月6日 星期日

根據hibernate configuration file建立table schema

程式範例如下:

package mytest;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class SchemaExportTester {

public static void main(String[] args) {
new SchemaExportTester().createSchema();
}

private void createSchema() {
Configuration cfg = new Configuration().configure();
SchemaExport schemaExport = new SchemaExport(cfg);
schemaExport.setOutputFile("schema.sql");
schemaExport.create(true, true);
System.out.print("ok");
}
}


其中
schemaExport.create(true, true);
第一個參數是表示是否要產生schema.sql,第二個參數是表示是否要在database立建立table。

2008年6月2日 星期一

MySQL Character Encoding Configuration

It's common practice that the MySQL configuration file, in *nix systems is located in /etc/mysql/my.cnf
in windows, which is located in %MYSQL_HOME%\my.ini

[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
character-set-server = utf8
collation-server = utf8_general_ci

XWiki encoding

web.xml:

<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.xpn.xwiki.web.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>


xwiki.cfg:

xwiki.encoding = UTF-8

XWiki: XWikiPreferences:
Default Language:en

2008年5月20日 星期二

用Windows Live Writer試試post

windows live write

還不錯用耶

2008年2月14日 星期四

Tomcat 5.5中設定JNDI resource的方法

1. $TOMCAT_HOME/conf/server.xml:
<GlobalNamingResources>
...
<Resource name="bean/CalendarFactory"
type="java.util.GregorianCalendar"
auth="Container"
factory="org.apache.naming.factory.BeanFactory"/>
</GlobalNamingResources>

2. $TOMCAT_HOME/conf/context.xml
<Context>
...
<Resource name="jdbc/AboveeDB" auth="Container"
type="javax.sql.DataSource" username="pp50" password="pp50"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://robbibm:1433/pp50p2"
maxActive="8" maxIdle="4"/>
</Context>

3. $TOMCAT_HOME/conf/web.xml
</web-app>
...
<resource-env-ref>
<description>
Fake up a Factory for Calendar objects
</description>
<resource-env-ref-name>
bean/CalendarFactory
</resource-env-ref-name>
<resource-env-ref-type>
java.util.GregorianCalendar
</resource-env-ref-type>
</resource-env-ref>
</web-app>

4. JSP client程式片斷
<%
javax.naming.Context ctx = new javax.naming.InitialContext( );
java.util.Calendar calendar = (java.util.GregorianCalendar)
ctx.lookup("java:comp/env/bean/CalendarFactory");
out.println(calendar.getTime());
%>

2008年2月4日 星期一

note

eclipse font: Georgia 16, Microsoft Sans Serif 14
package: nimble, brisk


2008年1月16日 星期三

找出某特定class到底存在哪個jar檔裡

Linux:
find ./ -name "*.jar" |xargs -t -i jar -tvf {}|grep TheClass

Windows + Cygwin
for %f in (*.jar) do jar -tvf %f |grep TheClass

2008年1月4日 星期五

在fedora上安裝java 6

1. 自sun網站download jdk-6u3-linux-i586-rpm.bin
2. chmod 755 jdk-6u3-linux-i586-rpm.bin
3. su, 改用root登入
4. 執行./jdk-6u3-linux-i586-rpm.bin
5. 執行alternatives命令指示fedora改用Sun的JVM:
alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_03/bin/java 100
alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_03/bin/jar 100
alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_03/bin/javac 100
其他jdk相關可執行檔也可以相同方式處理。
6.最後需要配置alternative去使用Sun的JVM做預設的JVM。執行以下命令:
/usr/sbin/alternatives --config java
7.有時執行java webstart時,會出現以下錯誤訊息:
java.lang.UnsatisfiedLinkError: /usr/java/jdk1.6.0_03/jre/lib/i386/libdeploy.so: libstdc++.so.5: cannot open shared object file: No such file or directory
執行yum install libstdc++.so.5就可以了。

8. 安裝jre及firefox jre plugin,參考以下網址:
http://java.com/zh_TW/download/help/5000010500.xml#rpm

9. 安裝完jre後,至/usr/lib/firefox-2.0.0.10/plugins執行以下命令:
ln -s /usr/java/jre1.6.0_03/plugin/i386/ns7/libjavaplugin_oji.so .
如此可讓firefox執行applet