Maven annoyances: “Web.Xml Is Missing And Is Set To True”

So you are getting this error in your Eclipse IDE

web.xml is missing and <failOnMissingWebXml&gt> is set to true

Here how you fix this silly error

Right click the project->Java EE Tools->Generate Deployment Descriptor Stub

Voila. Problem fixed.

JVM threads getting locked when using IPv6 methods with IPv4 address

Do you have threads locked in a state that looks like this?

java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
- waiting on <26457185> (a java.util.HashMap)
at java.lang.Object.wait(

This usually happens when the applications trying to use IPv6, when the environment is really only configured for IPv4.

The solution is to configure the the Java processes to prefer the IPv4 stack. The default is to prefer the IPv6 stack. This can be done by specifying a JVM argument to prefer IPv4.

A detailed explanation of this problem can be found here:

How to enable JMX on Tomcat running on EC2 (behind a firewall)

Step 1: Copy catalina-jmx-remote.jar into Tomcat’s lib folder. This jar file is available in the extras folder of Tomcat’s binary distribution.

Step 2: Modify Tomcat’s server.xml by adding a new Listener entry.

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" 
rmiRegistryPortPlatform="9090" rmiServerPortPlatform="9091"/>

Step 3: Open both of these ports in your firewall. Ports 9090 and 9091 and just examples, you can choose to use any port numbers you like.

Step 4: Add the following options to Tomcat startup script. 
-Djava.rmi.server.hostname=public-ip (or public dns)

All done! Restart Tomcat and connect to it using jconsole or visualvm from a remote system.

Installing Oracle JDK and Tomcat on an EC2 Linux instance

Installing Java JDK on Amazon Linux AMI

Most likely you already have Open JDK installed on you EC2 instance. You will have replace OpenJDK with Oracle JDK. Here is how you do it.

Perform all the operations below as root.Get the latest Oracle (Sun) JDK rmp binary from the Oracle website and copy it to the EC2 instance.

# make it exec
chmod +x jdk-6u34-linux-x64-rpm.bin

# Install Java
sudo ./jdk-6u34-linux-x64-rpm.bin

# Check if the default java version is set to sun jdk
# Normally it says OpenJDK
java -version

# Create another alternative for Java for Sun JDK
sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_34/bin/java 20000

# Set the SUN JDK as the default java
sudo /usr/sbin/alternatives --config java

# Verify if change in SDK was done.
java -version

Installing Tomcat on Amazon Linux AMI

# Check if tomcat is already installed 
yum info tomcat6

# To install tomcat6, run the following command
yum install tomcat6

# Start Tomcat as follows
service tomcat6 start

Tomcat has now been installe in /usr/share/tomcat6/

# To check that Tomcat has indeed started and is listening on port 8080:
fuser -v -n tcp 8080

#To have Tomcat start automatically on instance reboot
chkconfig --level 345 tomcat6 on 

Tomcat by default runs on port 8080. Traffic can be redirected from port 80 to 8080 by running the following commands:

/sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
/sbin/service iptables save