วันพุธที่ 6 มกราคม พ.ศ. 2553

Automatically signing .jar files in NetBeans

ref: Automatically signing .jar files in NetBeans
From : http://ezzatron.com

Automatically signing .jar files in NetBeans

Just a quick article on something I struggled to find a good example for – configuring NetBeans to sign a .jar file after compilation is complete.

This is very handy, for example, when developing an applet that requires permission to access the file system. This requires the applet to be “signed” using the jarsigner utility, and this quickly becomes a tedious step when testing changes made in your applet in the browser itself.


I’m assuming that since you’re reading this article you have basic knowledge of Java and the keytool and jarsigner utilities. If not, there is a good introduction here.

Please note that this how-to is intended for a development environment situation only. Before deploying to a production environment you should read up on the best practices and security implications of the .jar signing process.

Step 1: Setting up your keystore

For this step we will be using the keytool utility distributed with your JDK. This will most likely be in the bin directory of your JDK installation.

Assuming keytool is in your system path, run the command:

keytool -genkey -alias -keystore -validity 36500
Replacing with a suitable alias, and with the filename you’d like for your keystore.

You will then be prompted for a number of inputs. For a test setup, use the following answers:

Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]:
What is the name of your organizational unit?
[Unknown]:
What is the name of your organization?
[Unknown]:
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
[no]: y

Enter key password for <>
(RETURN if same as keystore password):
This will create a keystore file at which we will use in the next step to sign .jar files. Remember the passwords you used in this step as you’ll need them very soon.

The -validity 36500 section simply specifies that we want this key to last for a very long time (100 years to be exact). This is fine in a development environment as you probably don’t want to have to regenerate new keys all the time, but in a production environment this would obviously be much shorter. The -validity value is specified in days.

Step 2: Configuring your NetBeans project

In this step we will be editing two configuration files from your NetBeans project; project.properties and build.xml.

The project.properties file should be located in the nbproject directory of your NetBeans project, and the build.xml should be in the main project folder itself.

You can edit these files by hand, or you can do so in NetBeans itself by switching to the Files window.

Add the following lines somewhere in your project.properties file, substituting the relevant paths etc. (hint: your jarsigner utility should be in the bin directory of your JDK installation):

jarsign.jarsigner=
jarsign.keystore=
jarsign.storepass=
jarsign.keypass=
jarsign.signedjar=
jarsign.alias=
Add the following inside the block in your build.xml file:












Signed Jar '${jarsign.signedjar}' created

And that’s it. The next time you build your project, a signed copy of the .jar file should be created automatically at the path you specified. You should also see a confirmation message in the build output.

วันพฤหัสบดีที่ 8 ตุลาคม พ.ศ. 2552

Que Sera Sera What ever will be will be

Que Sera Sera What ever will be will be.
ประโยคประทับใจอีกประโยคหนึ่งที่โดนใจผมอย่างรุนแรง พลันกลับทำให้คิดได้ว่า อะไรจะเกิดมันก็ต้องเกิด พร้อมกับตอกย้ำความเชื่้อที่มีอยู่ในจิตใจว่าทำวันนี้ให้ดีที่สุด เพราะอะไรจะเกิดมันก็เกิด




โฆษณาไทยประกันชีวิต whatever will be will be (Que Sera Sera) - ดูวิดีโอทั้งหมด กดที่นี่

วันพุธที่ 7 ตุลาคม พ.ศ. 2552

Flash,Flex and Web3D

ด้วยความพยายามที่หลากหลายในการใช้งานไฟล์ X3D blog นี้เป็นอีกหนึ่งคนที่ศึกษาอะไรที่คล้ายๆกัน

SKP2X3D น่าสนใจทีเดียวเชียว

มาทำให้ Dreamweaver CS3 เห็น GSP ไฟล์กันเหอะนะ

ที่มา: Open .GSP file with Dreamweaver CS3

หลังจากที่เกิดอาการเซ็งกับการนั่งแก้ html tag ใน netbeans 6.7.1 ก็เลยคิดว่าอยากใช้ adobe dreamweaver CS3 ขึ้นมาตะหงิดๆ แต่ว่าทำไมมันไม่มี GSP ไฟล์หละเนี่ยทำไงดีว่าแล้วก็ไปเจอเข้ากับบล็อกนี้เค้าก็เลยเก็บเอามาฝากแต่อยากจะบอกว่าำตำแหน่ง config file เนี่ยเครื่องผมเป็น xp แต่มันเก็บใน Application Data/ folder ครับ

วันอาทิตย์ที่ 4 ตุลาคม พ.ศ. 2552

Update Netbeans 6.7.1 แก้ปัญหาการมองไม่เห็น Plugin ในgrails 1.1 แล้ว

หลังจากที่ใช้ netbean 6.5 อยู่มานานก็พอปัญหาหาว่า IDE ไม่สามารถลิงค์ library path ของ plugin ในgrails 1.1 ได้ ทำให้เวลาเขียนโค้ดมันจะฟ้องว่าเราเขียนผิดแต่ว่า คอมไพล์ได้ไม่มีปัญหาอะไรการใช้งานก็คงจะไม่ค่อยสะดวกแต่พอใช้การได้ไปเรื่อยๆ
จน เมื่อวานได้ลองเข้าไปตรวจสอบ เวอร์ชัน update ของnetbean ก็พบว่าได้เปลี่ยนมาเป็น 6.7.1แล้วซึ่งเค้าก็บอกว่า fix bug ตัวนี้สำหรับ grails 1.1 ขึ้นไปแล้วด้วย ว่าแล้วก็โหลดมาลงเลยครับ

netbeans 6.5 จะิเห็นว่ามันมองไม่เห็น library ของ plugin


แน่นอนว่าหน้านี้ก็ไม่เห็นเช่้นกัน

ปัญหาหลักๆก็คือ directory ที่ใช้เก็บ plugin มันถูกเปลี่ยนไปตั้งแต่ grails 1.1 ดังนั้นผมก็ทนใช้มันไปแบบยังไม่รู้ว่าจะแกยังไงดีจนเอาตัวใหม่มาลง netbeans 6.7.1 ก็พบว่า happy ครับ

นอกจากไม่มี error แล้วยังขึ้น suggestion ด้วยยิ้มเลยครับ

วันพฤหัสบดีที่ 1 ตุลาคม พ.ศ. 2552

Grails, GORM, Domain Classes and Enum

วันนี้มีปัญหาเรื่องการสร้าง enum ในเกรล์ ไปได้ข้อมูลดีๆมาจาก blog นี้


ด้วยการสร้างคลาส enum โดย java แล้วสร้างmethod ในการสร้าง arrayList ให้ Gorm access ได้นั้นนอกจากจะแก้ปัญหา enum ในเกรล์ได้แล้ว scaffold เองก็มองเห็นโดยที่ไม่ต้องทำอะไรเพิ่มเติมใน bootstrap หรือ config เลยทีเ่ดียว

Set up Tomcat 6.0 startup service บน UBUNTU

หลังจากทำตาม tutorial ต่างๆมากมายเพื่อให้สามารถ startup tomcat เองหลังจากที่ทำการ reboot OS โดยการเพิ่ม script ดังนี้

sudo vi /etc/init.d/tomcat

แล้วก็เขียน script ตามนี้

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

แล้วก็จัดการเปลี่ยน script ให้สามารถ execute ได้

sudo chmod 755 /etc/init.d/tomcat

แล้วก็เพิ่มstart up link ใน RC

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

ผลปรากฎว่ามันไม่ค่อยจะwork เท่าไหรกับ tomcat 6.0 โดย service มันจะถูกเรียกขึ้นมาได้ปกติแต่กลับทำงานไม่ได้ซึ่งคาดว่ามาจาก bug ของ tomcat 6.0 ที่มีปัญหาเมื่อ รันบน IPV6 ครั้นจะเอาIPV6 ออกก็อาจจะกระทบ service บางตัวที่รันบน IPV6 ก็เลยได้ solution มาว่าต้องเปลี่ยนให้มันรัน JSVC daemon แทน โดยการ compile jsvc ที่ได้มาก่อน

cd $CATALINA_HOME/bin tar xvfz jsvc.tar.gz
cd jsvc-src
autoconf
./configure
make
cp jsvc ..
cd ..

แล้วก็เปลี่ยน startup script ให้รัน JSVC แทน

#!/bin/sh
#
# Startup script for Tomcat, the Apache Servlet Engine
#
# chkconfig: 345 80 20
# description: Tomcat is the Apache Servlet Engine
# processname: tomcat
# pidfile: /var/run/tomcat.pid
#
# Mike Millson <*******@meritonlinesystems.com>
#
# version 1.02 - Clear work directory on shutdown per John Turner suggestion.
# version 1.01 - Cross between Red Hat Tomcat RPM and Chris Bush scripts

TOMCAT_PROG=tomcat
JAVA_HOME='/usr/java/jdk1.5.0_06'
CATALINA_HOME='/home/tomcat/'
DAEMON_HOME=$CATALINA_HOME/bin/jsvc
TMP_DIR=/var/tmp
CATALINA_OPTS=
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

# if TOMCAT_USER is not set, use tomcat like Apache HTTP server
if [ -z "$TOMCAT_USER" ]; then
TOMCAT_USER="tomcat"
fi

RETVAL=0

# start and stop functions
start() {
echo -n "Starting tomcat: "
chown -R $TOMCAT_USER:$TOMCAT_USER /home/tomcat/*
$DAEMON_HOME \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-Dcatalina.home=$CATALINA_HOME \
-Djava.io.tmpdir=$TMP_DIR \
-Djava.awt.headless=true \
-outfile $CATALINA_HOME/logs/catalina.out \
-errfile '&1' \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap
# To get a verbose JVM
#-verbose \
# To get a debug of jsvc.
#-debug \

RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
return $RETVAL
}

stop() {
echo -n "Stopping tomcat: "
PID=`cat /var/run/jsvc.pid`
kill $PID
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat /var/run/tomcat.pid
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
# Ugly hack
# We should really make sure tomcat
# is stopped before leaving stop
sleep 5
start
;;
*)
echo "Usage: $0 {startstoprestart}"
exit 1
esac

exit $RETVAL

เรียบร้อยโรงเรียนไทย
นิทานเรื่องนี้สอนให้รู้ว่าของใหม่ก็ไม่ดีเสมอไปเน้อ