The Answer to Life, the Universe, and Everything

Sunday, December 09, 2007

Maven2 deploy to other server

Create file settings.xml under .m2
<?xml version='1.0' encoding='utf-8' ?>
<settings>
<servers>
<server>
<id>scp-repository</id>
<username>cavalier</username>
<privateKey>C:\Program Files\PuTTY\auth\id_rsa</privateKey>
<passphrase>xxxxxx</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
</servers>
</settings>


Then add the following to pom.xml
<distributionManagement>
<repository>
<id>scp-repository</id>
<url>scp://192.168.0.xx/home/cav/repository</url>
</repository>
</distributionManagement>

maven2 java version

You might need to specify the compile java version by using generics etc in pom.xml file.

<project>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

Saturday, December 01, 2007

Eclipse3.3.1 OutOfMemory

Eclipse 3.3.1 has bug on memory part.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=92250

Edit the "eclipse.ini" to fix the issue.
-showsplash
org.eclipse.platform
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx768m
-XX:MaxPermSize=256m

Maven + Eclipse = Error?

If you face the something like the following error,
Unbound classpath variable: ‘M2_REPO/bouncycastle/bcmail-jdk14/132/bcmail-jdk14-132.jar



Select the Eclipse Project folder from the Navigator window view
Right Click and get the Project Properties.
Select the tree item named “Java Build Path”
Push the button on the Right that says Add Variables.
Then Push the button that says Configure Variables.
Then push the New button
Add a new variable named M2_REPO and map it to the directory that contains the repository above.
Exit back to the “New Variable Classpath entry” dialog.
Select the M2_REPO variable and click extend
Select a jar file and exit.

Maven2 : Adding jar to local repos

This is how you can add the Non globally installed jar to your local repos.
mvn install:install-file -DgroupId=<<$Group Name>> -DartifactId=<<$Project Name>> \
-Dversion=<<$S/W version>> -Dpackaging=jar -Dfile=<<$Path to the jar file>>

Friday, November 30, 2007

Trac Installation

For Ubuntu 7.10.

$ apt-get install trac
$ sudo mkdir /var/trac
$ cd /var/trac
$ trac-admin test initenv
$ chown -R www-data ./test

$ apt-get install libapache2-mod-python
$ vi /etc/apache2/sites-available/trac
--
Alias /trac "/usr/share/trac/htdocs/"

<Location "/tracsvn">
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracUriRoot "/tracsvn"
PythonOption TracEnvParentDir /var/local/trac
AuthType Basic
AuthName "DoJa Repository"
AuthUserFile /etc/subversion/passwd
Require valid-user
SSLRequireSSL
</Location>
--
$ a2ensite trac
$ /etc/init.d/apache2 reload

Subversion Installation

For Ubuntu 7.10
$ sudo apt-get install subversion libapache2-svn
$ sudo mkdir /var/svn
$ sudo svnadmin create /var/svn/$REPOS
$ sudo chown -R www-data:www-data /var/svn/$REPOS
$ sudo chmod -R g+ws /var/svn/$REPOS


Only allowing to access by SSL
$ sudo a2enmod ssl
$ sudo apt-get install ssl-cert

#In order to change the valid days up to 10years
#vi /usr/sbin/make-ssl-cert
--
openssl req -config $TMPFILE -new -days 365 -x509 -nodes -out $output -keyout $output > /dev/null 2>&1
--
$ sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
$ sudo chmod a+r /etc/apache2/ssl/apache.pem

$ cp /etc/apache2/sites-available/default /etc/apache2/sites-available/$SITENAME
$ sudo vim /etc/apache2/sites-available/$SITENAME
change:
NameVirtualHost *:443

add:
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM

Thursday, November 29, 2007

MySQL Encoding

You need to change params for the server and the client.
# Change MySQL server encode
# By calling the following SQL you can see the current encoding.
# show create table xxx;
# show variables like 'char%';

mysql$ alter table xxx character set utf8;
mysql$ alter table xxx change sub1 sub1 varchar(256) character set utf8;
mysql$ set names utf8;
mysql$ set character_set_database=utf8
mysql$ set character_set_server=utf8

#On the client to connet to DB set the following param in URL
jdbc:mysql://localhost/blojsom?autoReconnect=true&useUnicode=true&characterEncoding=utf-8

Bind Reload

Bind reload command differs from the 8 or 9.
#Bind8
#/usr/sbin/ndc reload

#Bind9
#/usr/sbin/rndc reload

Friday, November 23, 2007

Eclipse Heap Memory

This is how you can change the memory for Eclipse to use.

#vim $ECLIPSE_HOME/eclipse.ini
--
-vmargs
-Xms64m
-Xmx256m

Tomcat Heap Memory

Here is the how we can change the setting of the memory used for tomcat.

set CATALINA_OPTS="-Xms512m -Xmx512m"  (Windows)
export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)

Java:Loading the file

The dev environment and the actual service server are different and often face the problem of path to the config file with FileNotFound Exception or so. Here is a solution.

URL propXML = this.getClass().getResource(RESFILE);
Configuration config = new XMLConfiguration(propXML);


or

ClassLoader loader = Thread.currentThread().getContextClassLoader();
DOMConfigurator.configure(loader.getResource("log4j.xml"));

Friday, November 16, 2007

Ubuntu: Change Timezone

The way to change the timezone.

root # ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
root # date -d

Monday, August 13, 2007

Formats decimal numbers by Java

DecimalFormat df = new DecimalFormat("0000");
df.format(77);
#OUTPUT: 0077


DecimalFormat df = new DecimalFormat("####");
df.format(77);
#OUTPUT: 77


DecimalFormat df = new DecimalFormat("####%");
df.format(77);
#OUTPUT: 77%


DecimalFormat df = new DecimalFormat("'AA'####%");
df.format(77);
#OUTPUT: AA77%


DecimalFormat df = new DecimalFormat("\u00A5###,###");
df.format(7777);
#OUTPUT: \7,777

Thursday, August 02, 2007

Struts2 by Maven for Eclipse


mvn archetype:create -DgroupId=tutorial \
-DartifactId=tutorial \
-DarchetypeGroupId=org.apache.struts \
-DarchetypeArtifactId=struts2-archetype-starter \
-DarchetypeVersion=2.0.1-SNAPSHOT \
-DremoteRepositories=http://people.apache.org/maven-snapshot-repository

cd tutorial
mvn -Dwtpversion=1.0 eclipse:eclipse

Monday, July 30, 2007

Tomcat & MySQL connection Error

Long absense after establishing the connection to MySQL from Hibernate, you might face the error below:
,406 ERROR JDBCExceptionReporter - Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTIOROR JDBCExceptionReporter - Communications link failure due to underlying exception

java.io.EOFException
STACKTRACE:

java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
.....


Then you can add the following setting in configuration file of hibernate.
jdbc:mysql://localhost:3306/ichannel?autoReconnect=true

Wednesday, June 27, 2007

UnknownHostException @ Tomcat


#vim /etc/hosts

--
192.168.0.100 hostname
--

Protocol Analyzer in CUI

For CUI protocol analyzer,

#apt-get install tshark
#tshark -i eth0 -w `date "+%Y%m%d_capture.pcap"` -R "tcp.port==8080"

-w : output file
-R : filter

Friday, June 22, 2007

Maven with Eclipse A-Z

The simplest A-Z for Maven with Eclipse.
$mvn archetype:create -DgroupId=xx.xx.XX -DartifactId=AppName -Dversion=0.0.1
$mvn eclipse:add-maven-repo -Declipse.workspace=/home/user/workspace
#Move to the project root folder, then..
$mvn eclipse:eclipse -DdownloadSources=true

It's done. Then import the project from the Eclipse and enjoy ;-)

Wednesday, June 20, 2007

AccessControlException By Java

When you deploy the contents you might face the AccessControlException which is cased by java security manager. By Ubuntu packaged tomcat5.5, you can edit the policy file.

$sudo vim /etc/tomcat5.5/policy.d/99examples.policy

grant codeBase "file:${catalina.home}/webapps/gprs/-" {
permission java.security.AllPermission;
}


The example above is the most loose security setting.

Hibernate cfg.xml file

hibernate.cfg.xml file not found issue is the one which troubles us often when we create the web app with hibernate. Here is the workaround code for this issue.

File file=
new File(getServletContext().getRealPath("/WEB-INF/classes/hibernate.cfg.xml"));
SessionFactory sessionFactory =
new Configuration().configure(file).buildSessionFactory();

Sunday, June 17, 2007

Ubuntu Java configuration

In case you need to change the version of java runtime environment which has been installed on you machine. It's simple as this,
$  sudo /usr/sbin/update-alternatives  --config   java

Wednesday, June 13, 2007

Ubuntu Default editor change

sudo update-alternatives --config editor

Ubuntu cron

Crontab on Ubuntu doesn't work with normal grammer. You need to add.
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin

command > /dev/null 2>&1

Tuesday, June 12, 2007

Maven2 with Hibernate

Maven cannot solve the dependency regarding jta as it is released by Sun and based upon their binary license it cannot be deployed on the maven repository.

You will see something like this below.
1) javax.transaction:jta:jar:1.0.1B
Try downloading the file manually from:
http://java.sun.com/products/jta
Then, install it using the command:
mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta \
-Dversion=1.0.1B -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) RssUpdater:RssUpdater:package:0.0.1
2) org.hibernate:hibernate:jar:3.2.4.ga
3) javax.transaction:jta:jar:1.0.1B
1 required artifact is missing.
for artifact:
RssUpdater:RssUpdater:package:0.0.1
from the specified remote repositories:
codehaus.org (http://snapshots.repository.codehaus.org/org/codehaus/mojo/),
maven.seasar.org (http://maven.seasar.org/maven2),
central (http://repo1.maven.org/maven2)



In order to avoid this, download jta and deploy it onto your local maven repos.

mvn install:install-file \
-Dfile=./jta-1_0_1B-classes.zip \
-DgroupId=javax.transaction \
-DartifactId=jta -Dversion=1.0.1B \
-Dpackaging=jar

Thursday, June 07, 2007

Ubuntu webdav

The problem probably you face as followed.
[Sat May 19 13:20:21 2007] [notice]
Apache/2.2.3 (Ubuntu) DAV/2 PHP/5.2.1 configured
-- resuming normal operations
[Sat May 19 13:20:53 2007] [error] [client xx.xxx.xxx.xx]
Could not DELETE /davhome/show.txt due to a failed precondition
(e.g. locks). [500, #0]
[Sat May 19 13:20:53 2007] [error] [client xx.xxx.xxx.xx]
The locks could not be queried for verification against a possible
"If:" header. [500, #0]
[Sat May 19 13:20:53 2007] [error] [client xx.xxx.xxx.xx]
Could not open the lock database. [500, #400]
[Sat May 19 13:20:53 2007] [error] [client xx.xxx.xxx.xx]
(13)Permission denied: Could not open property database. [500, #1]


Then..
$ sudo touch /var/lock/apache2/DAVLock
$ sudo chown www-data /var/lock/apache2/DAVLock

Tuesday, June 05, 2007

NW setting of Ubuntu on VMPlayer

This is small note of how to set network setting of "vmx" for Ubuntu as it didn't work at the original one.
#ethernet0.virtualDev = "vmxnet" <- Comment this line as it doesn't recognize device.
ethernet0.virtualDev = "e1000"


Then
#vim /etc/network/interface
auto eth0
iface eth0 inet dhcp

Thursday, May 17, 2007

Commons Digester Variable

The variable in xml data can be converted with Digester with the easy following codes.
Digester digester = DigesterLoader.createDigester(getURL(ruleFile));
Map vars = new HashMap();
vars.put("hello","Czesc!");
MultiVariableExpander expander = new MultiVariableExpander();
expander.addSource("$", vars);
Substitutor substitutor = new VariableSubstitutor(expander);
digester.setSubstitutor(substitutor);

Tuesday, May 15, 2007

Commons Lang toString()

Jakarta Commons Lang support the reflection for toString() which need to synchronize with the changes made for the object model.

public String toString(){
return ReflectionToStringBuilder.toString(this);
}


For the customization of the output,
public String toString(){
return ReflectionToStringBuilder.toString(this,ToStringStyle.MULTI_LINE_STYLE)
.append("lastName",lastName).append("firstName",firstName).toString();
}

Sunday, May 13, 2007

Encoding to 3gp file for mobile phones

If h/s support AAC.
#ffmpeg -i infile.mpeg -vcodec mpeg4 -r 15 -b 128k -s qcif -acodec aac -ar 8000
-ac 1 -ab 13 -f 3gp -y output.3gp


If not
ffmpeg -i infile.mpeg -vcodec mpeg4 -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000
-ac 1 -ab 13 -f 3gp -y output.3gp


For video editing on Linux, LiVES would be very nice.

Monday, March 19, 2007

Tomcat JkShmFile

Under the default config, you might get error when you boot up the tomcat saying,

jk_child_init::mod_jk.c (2317): Attachning shm:/etc/apache2/logs/jk-runtime-status errno=2

Write the following in /etc/apache2/mod-available/jk.load
JkShmFile /var/log/apache2/jk-runtime-status

Friday, January 05, 2007

Beautiful Font

Download M+font from http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/download/index.html#download

then follow..
% sudo apt-get install fontforge
% tar xvfz mplus-TESTFLIGHT-012.tar.gz
% cd mplus-TESTFLIGHT-012
% sudo cp /usr/share/fonts/truetype/ipa/ipag.ttf .
% sudo fontforge -script m++ipa.pe
% sudo mkdir /usr/share/fonts/truetype/mplus
% sudo mv M*IPAG.ttf /usr/share/fonts/truetype/mplus/.
% sudo fc-cache -f -v /usr/share/fonts/truetype/mplus