วันพฤหัสบดีที่ 15 มกราคม พ.ศ. 2552

Can't start Tomcat after install VMware server.

Today (It is not real and I'm lazy to update my blog ==") I'm astonished at why i cannot start Tomcat.
Previously, I offen use Jetty to run my web application because It is fast and has great Maven plugin integreated.
This is exception.
SEVERE: StandardServer.await: create[8005]:
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.(ServerSocket.java:185)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)
at org.apache.catalina.startup.Catalina.await(Catalina.java:630)
at org.apache.catalina.startup.Catalina.start(Catalina.java:590)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

I knew port 8009 and 8005 is used by another process but i don't know what process use.
Then I searched for process using this port.

sudo netstat -p -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:902 *:* LISTEN 6325/vmware-authdla
tcp 0 0 *:8333 *:* LISTEN 6466/vmware-hostd
tcp 0 0 localhost:8307 *:* LISTEN 6466/vmware-hostd
tcp 0 0 localhost:ipp *:* LISTEN 5069/cupsd
tcp 0 0 localhost:62168 *:* LISTEN 7621/wish8.5
tcp 0 0 *:8222 *:* LISTEN 6466/vmware-hostd
tcp6 0 0 localhost:6880 [::]:* LISTEN 8861/java
tcp6 0 0 localhost:8005 [::]:* LISTEN 6322/webAccess
tcp6 0 0 [::]:22214 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:8008 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:netbios-ssn [::]:* LISTEN 5387/smbd
tcp6 0 0 localhost:45100 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:8009 [::]:* LISTEN 6322/webAccess
tcp6 0 0 [::]:47698 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:8308 [::]:* LISTEN 6322/webAccess
tcp6 0 0 [::]:microsoft-ds [::]:* LISTEN 5387/smbd


Then I used ps command to find what webAccess is?

ps -ef | grep webAccess
root 6312 1 0 19:30 ? 00:00:00 /bin/sh /usr/bin/vmware-watchdog -s webAccess -u 30 -q 5 /usr/lib/vmware/webAccess/java/jre1.5.0_15/bin/webAccess -client -Xmx64m -XX:MinHeapFreeRatio=30 -XX:MaxHeapFreeRatio=30 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/common/endorsed -classpath /usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/bootstrap.jar:/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/commons-logging-api.jar -Dcatalina.base=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Dcatalina.home=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Djava.io.tmpdir=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start
root 6322 6312 0 19:30 ? 00:00:10 /usr/lib/vmware/webAccess/java/jre1.5.0_15/bin/webAccess -client -Xmx64m -XX:MinHeapFreeRatio=30 -XX:MaxHeapFreeRatio=30 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/common/endorsed -classpath /usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/bootstrap.jar:/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/commons-logging-api.jar -Dcatalina.base=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Dcatalina.home=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Djava.io.tmpdir=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start


I got VMware using Tomcat to run webAccess.
I chose to change Tomcat ports of VMware. I prefer this approach because I do not change other Tomcat ports again. (yes, It includes JBoss too)

To change Tomcat ports.
1 edit server.xml at /usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/conf/server.xml.
2 change file mode to writeable.
sudo chmod a+w server.xml

3 find and change 8009 and 8005 ports to others.
4 save and change file mode to old mode.
sudo chmod a-w server.xml

5 restart service or reboot you OS.

วันเสาร์ที่ 3 มกราคม พ.ศ. 2552

Other ways to run Maven on Eclipe.

M2eclipse is excellent Maven tool for Eclipse.
I always use hotkey Shift + Alt + X M to run the last maven goals of Maven Build projects.
example First time you run "compile goal" of MyProject. Next time you want to run with other goals. If you use this hotkey, It will run "compile goal" again. You must move a mouse, right click on project, then select Run as Maven builds ... and key the new goal that you want. It is inconvenient.

Today I read Eclipse integration with Grails. In the step Adding domain classes etc, It shows the way to use External Tools to run grails command. It can adapt to run maven goals.
1 Run -> External tools -> External tools configuration ... .
2 Select Program and new launch configuration.
3 Enter a name of "Maven".
4 Browse file system for the location of mvn command that you have installed.
5 Set the working directory to "${project_loc}".
6 Set the arguments as "${string_prompt}".
7 Under the "Refresh" tab, set to refresh the "project containing the selected resource" upon completion.
8 Under the "Common" tab, tick "Display in favorites menu".
9 I set hotkey Shift + Alt + X S to Runs the last launched external Tool.

Every time you use thes hotkey, Eclipe will always ask you what is the goals you need to run.
You can type any maven goals.