Jar scanner for finding jars

Hi All,

I am very happy to share a tool written by me, I have named it Archive Scanner, As the name suggest this tool will help to search for Java classes jar names. Sometime we spend lots of time searching for a jar name, and looking here and there. I can understand this pain as I have faced so many times. So it is a sort of tool I have gifted to myself and all you out there.

This tool(jar) is self executable, only things is that you need to set up a java environment to use that.
It works on JDK.1.5 or later. Please download from the below file.

Tool DownLoad:
archive scanner

Steps to Use:
– First of all save the Jar it to some location. e.g c:\myTool
– Open command Console and change the directory to the location where Jar has been saved
– Set Java Home (ignore if already defined)

– Run the below java command
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName Classwriter.class
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName Classwriter
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName com/bea/objectweb/asm/ClassWriter
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName com.bea.objectweb.asm.ClassWriter
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName com.bea.objectweb.asm.ClassWriter.class

Hope this help, Please give your suggestions or your experience with this tool, this would help me to apply any sort of improvements further.

Happy learning.


Thanks
R Vashi

java.lang.OutOfMemoryError: PermGen space

Hi All,

Few days back I was reading one of the article of my all time favorite guru(Jaysen sharma), So I would like to share that in this article.

In case of OutOfMemoryError in PermGen Sapace …increasing only the Heap Size will not solve anything…

Formula:

(OS Level)Process Size = Java Heap Native Space (2-3% OS related Memory)

PermSize : It’s a Native Memory Area Outside of the Heap, Where ClassLoading kind of things happens…. In an operating System like Windows Default Process Size is 2GB (2048MB) default (It doesn’t matter How much RAM do u have 2GB or 4GB or more)…until we don’t change it by setting OS level parameter to increase the process size..Usually in OS like Solaris/Linux we get 4GB process size as well.

Now Lets take the default Process Size=2GB (Windows), Now if you have set the -Xmx512M, we can assume that rest of the memory 1536 Mb is available for Native codes.

(ProcessSize (-) HeapSize) = Native (+) (2-3% OS related Memory)

2048 MB (-) 512 MB = 1536 MB

THUMB RULES:

MaxPermSize = (Xmx/3) —- Very Special Cases (One Third of maximum Heap Size)

MaxPermSize = (Xmx/4) —- Recommended (One Fourth Of maximum Heap Size)

So finally you need to increase the PermGen Size… like -Xmx1024m -Xms1024m -XX:MaxPermSize256m

But again these are not the Final values … It depends on ther Environments

Thanks

R Vashi.

set java heap size in Tomcat

Hi All,

Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,

set CATALINA_OPTS=-Xms512m -Xmx512m  (Windows, no "" around the value)
setenv CATALINA_OPTS "-Xms512m -Xmx512m"  (tcsh/csh, "" around the value)
export CATALINA_OPTS="-Xms512m -Xmx512m"  (ksh/bash, "" around the value)

In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. What is the difference between CATALINA_OPTS and JAVA_OPTS? The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don’t want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.

Note: Always make sure all the java objects should garbage collected, specially JDBC objects.


Thanks
R Vashi.

start and stop Tomcat from ANT

To Start and stop tomcat using Ant is fairly very simple, 
1.Create a build.xml file.
2. Set TOMCAT_HOME=[TOMCAT INSTLL DIR] in Classpath of the System
3. Write the below ant task
<target name="startTomcat">
    <java jar="${tomcat_home}/bin/bootstrap.jar" fork="true">
        <jvmarg value="-Dcatalina.home=${tomcat_home}"/>
    </java>
</target>

<target name="stopTomcat">
    <java jar="${tomcat_home}/bin/bootstrap.jar" fork="true">
        <jvmarg value="-Dcatalina.home=${tomcat_home}"/>
        <arg line="stop"/>
    </java>
</target>

--
Thanks

Deployment in Tomcat using ANT Script

Hi

Open build.xml, and add the below Task def and Ant Task.

[taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/]

[deploy url=”${manager.url}”
username=”${manager.username}”
password=”${manager.password}”
path=”/${name}”
war=”file:/${dist.dir}/${name}.war” /]

[target name=”deploy” depends=”package-web” if=”tomcat.home”
description=”unwar into the servlet container’s deployment directory”]

[unwar src=”${webapp.dist}/${webapp.war}”
dest=”${tomcat.home}/webapps/${webapp.name}”/]

[/target]

JDBC Datasource in Tomcat

Hi

To enable data source in Tomcat 6 is very simple, All you have to do is to goto [Tomcat-Home]/conf/server.xml

[Context docBase=”TestDB” path=”/TestDB” reloadable=”true” source=”org.eclipse.jst.j2ee.server:TestDB]
[Resource auth=”Container” connectionCacheProperties=”{MaxStatementsLimit=10, MinLimit=3, InitialLimit=1, ValidateConnection=true, ConnectionWaitTimeout=10, MaxLimit=10}”
driverclassname=”oracle.jdbc.driver.OracleDriver” factory=”oracle.jdbc.pool.OracleDataSourceFactory”
name=”JNDI_NAME” password=”PASSWORD” scope=”Shareable”
type=”oracle.jdbc.pool.OracleDataSource” url=”jdbc:oracle:thin:@127.0.0.1:1521:MYDB”
user=”USER_NAME”/]
[/Context]

Now add the below API in your java class to get connection from this data source.

public OracleConnection getConnectionFromPool() throws SQLException,
NamingException {
String dataSourceName = “JNDI_NAME”;
Context initContext = new InitialContext();
DataSource ds=null;
try {
ds = (DataSource) initContext.lookup(“java:/comp/env/” + dataSourceName);
} catch (Exception e) {
throw e;
}
}
OracleConnection con = (OracleConnection) ds.getConnection();

return con;
}

Enable SSL in Tomcat

Step 1
Windows[goto Command]
%JAVA_HOME%\bin\keytool -genkey

Enter all the details which keytool is going to prompt. (rememeber the password)

once you done, please go to your [USER_HOME](document & settings), locate the .keystore.

Copy this file and paste in tomcat root folder.

Step 2
Open [tomcat_home]/conf/server.xml

uncomment the SSL config entry. And configure the SSL certificate info.[see beloe]
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile=”.keystore” keystorePass=”12345678″ />

Step 3
Start tomcat
[tomcat_home]/bin/start-up.bat
in tomcat console you will see a message
INFO: Initializing Coyote HTTP/1.1 on http-8443

Now open a new browser and type https://localhost:8443/.

Thanks
Avi