Skip to main content

Tomcat configuration

1. How to deploy web application in tomcat 
 Create a war file and deploy it in tomcat->webapps folder.Restart tomcat and write localhost:8080/YOURWEBAPPNAME. 
 2. Add jndi in tomcat 
 <Resource name="jdbc/myDB" auth="Container"
 type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
 username="admin" password="admin"
 in web.xml 
 <description>DB Connection</description>
 3. Add user with manager role in tomcat   Tomcat-users.xml 
 <role rolename="manager"/>
 <user username="admin" password="admin" roles="manager"/>
 4.Solve OutOfMemoryError in tomcat 
 For the exception java.lang.OutOfMemoryError: PermGen space,
 you need to add one more option in JAVA_OPTS called MaxPermSize. After adding these options, JAVA_OPTS looks like in the file.
 export JAVA_OPTS="-server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m $JAVA_OPTS". 
 5. Configuring tomcat in eclipse 
 Open eclipse and then click window-> show view->other-> servers.
 Then right click on it and add new server. Select Apache tomcat -> browse your tomcat folder and finish.
 Tomcat server is added and to start the server right click on it and click start. 
 6. Change tomcat default port 
 open server.xml file and then find the line
 <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 
 change the connector port 8080 to 8090 i.e. 
 <Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 
 Then restart tomcat server. 
 7. SSl configuration in tomcat 
 Create a keystore file to store the server's private key and self-signed certificate by using KeyTool command: Windows:
 %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA 
 Unix:   $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA 
 Enter keystore password:tomcat
 Re-enter new password:tomcat
 What is your first and last name?Biswajit Das
 What is the name of your organizational unit?aaa
 Next, edit Tomcat's conf/server.xml to enable the HTTPS connector.
 Look for a connector that looks like this:   
 <!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true"   clientAuth="false" sslProtocol="TLS" />   --> 
 uncomment the line now it look like 
 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="conf/keystore" keystorePass="tomcat" /> 
 keystorePass is your password that you have mentioned to your keystore


Popular posts from this blog

jdbc mysql example in java

Here’s an example to show you how to connect to MySQL database via a JDBC driver.To connect to MySQL from Java, you have to use the JDBC driver from MySQL. You find the latest MySQL JDBC driver under the following URL:
Create a example database and named it test.Now create a a table name it user. Create table user ((userid INT NOT NULL AUTO_INCREMENT,
username VARCHAR(30) NOT NULL, PRIMARY KEY (userid)); Now add the record in your table; Now create a project in eclipse and mysql-connector jar in its classpath.package com.test;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; publicclass JavaJDBCExample { private Connection connect = null; private Statement statement = null; private ResultSet resultSet = null; publicvoid readDatabase() { try { // this will load the MySQL driver Class.forName("com.mysql.jdbc.Driver"); // setup the connection wi…

lucene example

In simple words: it parses a text and without saving the text the framework can search inside it. It keeps track of terms used inside the text. Of course you can optionally save the text into your <a href="" data-cke-saved-href="">lucene index</a>.

 Lets take an example.

 I have created a database and a table named it 'city'.

 create table `city` (

 `id` bigint (20),

 `city_name` varchar (765)


 Now I have added two record Kolkata,Delhi in the database.

 Now create a java project and add lucene-analyzers-common-4.0.0.jar,lucene-core-4.0.0.jar,lucene-queries-4.0.0.jar,lucene-queryparser-4.0.0.jar and mysql-connector-java-5.1.22-bin.jar in the project.

 create a java class named LuceneTest  and write the following.

LuceneTest .java

 package com.test;

singleton design pattern

Java Singleton design pattern is one of the design pattern which suggest that only one instance of a Singleton object is created by the JVM. This is useful when exactly one object is needed to coordinate actions across the system Example: public class Singleton{ privatestatic Singleton singleton = null; private Singleton(){ } publicstaticsynchronized Singleton getInstance( ) { if(singleton == null) { singleton = new Singleton(); } returnsingleton; } publicvoid test( ) { System.out.println("test"); } @Override protected Object clone() throws CloneNotSupportedException { // TODO Auto-generated method stub returnnew CloneNotSupportedException(); } } publicclass SingletonTest { publicstaticvoid main(String[] args){ Singleton singleton = Singleton.getInstance(); try{ Singleton