Pages Navigation Menu

Coding is much easier than you think

How To Change Default Port number of Tomcat Server?

Posted by in Java, Tomcat

Red race track from an old Olympic stadium
 
Tomcat by default runs on port number 8080, but many times other Java application also uses 8080 and starting tomcat may result in java.net.BindException. In order to avoid this exception you can change default port of tomcat from 8080 to some other port
 
Do read
What is a Memory Leak and Garbage Collector in java?
Java Heap Dump Analysis using Eclipse Memory Analyzer (MAT)
How to find the JDK target version from a .class file?
 

Steps in changing the Tomcat Port

 
Go to the installation directory of Tomcat Server and then open folder named “conf” and locate the file server.xml and Search for the entry shown bellow:
 

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

 
Change the value of attribute port to your desire value and restart the Tomcat Server.
 

<Connector port="8089" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

 

Read More

How to increase JVM heap size in Eclipse

Posted by in Eclipse, Java, Jboss, Tomcat | 1 comment

 
To avoid getting java.lang.OutOfMemoryErrors, while running web application, we should increase heap size allocated by the JVM by using command line options.
 

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

 

To do this, follow these steps:

1. Open the Server Configuration in Eclipse by double-clicking on the Server instance.
 
Server
 

2. Click on “Open launch configuration” link
 
Increase JVM max heap size eclipse
 
3. Click on the Arguments tab and add the following command at the end of VM arguments: -Xms128m –Xmx1024m.
 
Increase JVM max heap size eclipse
 

These values may vary, depending on requirement/available memory

 
If you are not using any server, you can type the following on the command line before you run your program:

java -Xms64m -Xmx1024m MyProgram

 

Note:

  • Do not set -Xmx to too small value
  • Set -Xms to a small value

Setting -Xmx to small value mostly leads to OutOfMemoryErrors, because this is the maximum amount of memory you are allocating for Java and it cannot utilize memory beyond the set value.

Also If you set -Xms to higher value you might run out of memory. So try to keep it to a small value like -Xms16m.
 

Read More

How to install Eclipse IDE and configure apache tomcat

Posted by in Eclipse, Tomcat

 

Downloading Eclipse

 
If you need to install Eclipse, you can download it from this location: http://www.eclipse.org/downloads/
 

Installing Eclipse

 
Once downloaded extract the files in the desired directory. When you extract the file, it creates a sub directory called “eclipse” in which you can find the eclipse.exe application. You can double click on this to launch Eclipse.
 
Eclipse
 

Setup Apache Tomcat :

 
You can download the latest version of Tomcat from http://tomcat.apache.org/. Once you downloaded the installation, unpack the file into a desired directory. For example in D:\Study\Java\apache-tomcat-7.0.23
 
Now open Eclipse IDE and make sure you are in Java EE perspective; Now right click -> New -> Server in “Servers” area.
 
Create server in Eclipse
 
Now you could see list of servers that can be configured in Eclipse. You will find Tomcat v7.0 Server under “Apache” folder as shown below.
 
Ecplise tomcat server configuration
 
Click next, and fill in your Tomcat installation directory:
 
Tomcat installation folder
 
Click Finish, now the configured Apache Tomcat Server will be displayed in the “Servers” view as shown below.
 

Start Server

 
Now start and stop it to ensure that it is working properly.
 
Starting Tomcat
 
That’s all on how setup eclipse IDE and configuring apache tomcat.
 

Read More