Archive for the ‘Lang Code’ Category

Eclipse can not add tomcat 6 server

Saturday, July 4th, 2009

While working with the system installed tomcat6, we have to change files in /usr/share/tomcat6/conf to global read/write.

  • Share/Bookmark

Eclipse can not start after installed WTP

Saturday, July 4th, 2009

It is because open file limit is not enough. After change open file limit to 10000, it works fine.

  • Share/Bookmark

How to change file limit in Fedora Linux

Saturday, July 4th, 2009

Add a file in /etc/security/limits.d/, say nofile.conf

*    soft    nofile    1024
*    hard    nofile    65535

Edit /etc/pam.d/login, adding the line:

session required pam_limits.so

we can change the open limit by:

unlimt -n 10000
  • Share/Bookmark

ulimit command

Saturday, July 4th, 2009

show current file limit:

ulimit -n

show all limit:

ulimit -a

show all hard limit:

ulimit -aH
  • Share/Bookmark

PHP object assign alway by reference

Saturday, April 4th, 2009

Different from what we discuss before about regular variable type, object assignment always by reference:

class A {
        public $a = 'a';
}

$a = new A();
$b = clone $a;
$c = $a;
$b->a = 'b';
echo $a->a, "\n";
$c->a = 'c';
echo $a->a, "\n";

Output:

a
c

We use clone to make a copy of object. Please note that default clone operation is shallow copy. You have to overload the __clone method if you want deep copy of the object.

  • Share/Bookmark

PHP return by reference

Saturday, April 4th, 2009

We can ask a function return by reference by adding a & before function declare. See example:

function & pass(& $a) {
        return $a;
}

function duplicate(& $a) {
        return $a;
}

$a = array('a'=>'a');
$b = duplicate($a);
$c = & pass($a);
$b['a'] = 'b';
echo $a['a'], "\n";
$c['a'] = 'c';
echo $a['a'], "\n";

output is:

a
c

You will see, the trick here is: don’t forget to put an ‘&’ before the function of assign operation. Otherwise, the assign operation will make a copy of the returned reference.

  • Share/Bookmark

temperary fix of Fedora 10 x86_64 snmpd segment fault

Wednesday, December 3rd, 2008

Due to the problem of Fedora 10 ’s new rpm 4.6, the snmpd can not start with a segment fault error.You can temperary work around this by adding a line to /etc/sysconfig/snmpd

OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a -I -hr_swinst"
  • Share/Bookmark

Set static ip on Fedora 9

Saturday, May 17th, 2008

disable “Network Manager” service, enable: “network” service. Then you can set the static ip by editing /etc/sysconfig/network-scripts/…

  • Share/Bookmark

Install an external jar into local Maven repository

Sunday, May 4th, 2008

Sometimes, you project will have dependency on a jar which is not in official maven repository, and maybe it is propriety jar file which will never be part of maven repository. In this case, you have to put it to your local repository your self to solve the dependency.

There is a install plug in to do this job, which is something like:

mvn install:install-file -DgroupId=<your_group_name>  \
-DartifactId=<your_artifact_name>  \
-Dversion=<snapshot>  \
-Dfile=<path_to_your_jar_file>  \
-Dpackaging=jar \
-DgeneratePom=true

For example, you want to install the danga’s memcached client plugin, you can do:

mvn install:install-file -DgroupId=com.danga \
-DartifactId=memcached \
-Dversion=2.0.1 \
-Dfile=java_memcached-release_2.0.1.jar \
-Dpackaging=jar \
-DgeneratePom=true

This will add the memcache jar into your local Maven2 repository under groupId com.danga and artifactId memcached, you can then edit your pom.xml adding this dependency.

However, the maven eclipse can not recognize it since it always search from public repository.

  • Share/Bookmark

Maven Project Layout

Saturday, May 3rd, 2008

src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project’s license
README.txt Project’s readme

  • Share/Bookmark