Saturday, 24 November 2012

HTTP Status 404 - / on tomcat


HTTP Status 404 - /

type Status report

message /

description The requested resource (/) is not available.

Apache Tomcat/6.0.26




When you choose to  "Start" your Tomcat and when you Open http://localhost/ in a browser: you will see a 404 error message.
This occurs because your eclipse fails to copy the ROOT files in the metadata folder and http://localhost/ will result in a 404 error. But, the error page comes from Tomcat, so it shows that Tomcat is running. The problem is that Eclipse doesn't copy the default Web application to the Eclipse/Tomcat folder. However, if you copy the ROOT files as described below, http://localhost/ will give the default Tomcat page.


Eclipse forgets to copy the default app (ROOT) when it creates a Tomcat folder inside the Eclipse workspace.
>> Go to C:\apache-tomcat-7.0.27\webapps,  copy the ROOT folder.
>>Go to your Eclipse workspace >> .metadata folder>>.plugins>>org.eclipse.wst.server.core>>wtpwebapps.
>>Paste ROOT (say "yes" if asked if you want to merge/replace folders/files). Then reload http://localhost/ to see the Tomcat welcome page.

Saturday, 17 November 2012

Access restriction: The type ResolverConfiguration.Options is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar

This error may occurs when your project is not able to identify your JRE system library. So the get the workaround you have to follow these steps.


-->Go to the project properties.
-->Remove the JRE System Library
-->Add it back :
                     Select "Add Library" and select the JRE System Library.

The main reason for this to happen is that if  you are trying to replace a standard class which ships with some different Java Version with one in the library you have.


Tuesday, 6 November 2012

permgen space error in ant








set ANT_OPTS as the system variable
with value
-Xms512m -Xmx1024m -XX:PermSize=1024m -XX:MaxPermSize=2048m

How to solve java Permgen Space error


You must have often come across something OutOfMemoryError: PermGen Space error. 

Let's first get in to a little detail of  what actually is permanent generation heap space and why Permgen Space error comes and how to handle this.

What is:-

                  There are two memory regions in the JVM: the heap and the stack. Local variables and methods reside on the stack, everything else on the heap.

The  heap memory is structured again into regions, called generations. 
The Java virtual machine is organized into three generations: a young generation, an old generation, and a permanent generation.
Most objects are initially allocated in the young generation. The old generation contains objects that have survived some number of young generation collections, as well as some large objects that may be allocated directly in the old generation. The longer an object lives, the higher the chance it will be promoted to an older generation.

Young generations are more garbage collected than older generations. 

However, there is also some separate heap space called permanent generation. Since it is a separate region, it is not considered part of the Java Heap space. Objects in this space are relatively permanent. Class definitions are stored here, as are static instances.
For the HotSpot Java VM, the memory pools for serial garbage collection are the following.

Eden Space (heap): The pool from which memory is initially allocated for most objects.
Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.





How:-

          
       The prime reason for the error is the deployment and undeployment of classes all the time .


Let's take the scenario of a web server.
When an application is deployed or undeployed, its class definitions and Classloader are respectively put into and removed from the permanent generation heap. The problem arises when the undeployment of classes happens and they are not fully garbage collected.

              Let’s say we have a class A, which is part of a jar in a web application that is deployed on some webserver. In the lib folder of the web server, there is some logging framework present, which has a Log class with the method abc(Class B) with which classes can be registered for logging. Let’s say that the class A gets registered by this method and the Log class starts keeping a reference to the B's  object. When the class A gets undeployed, it is still registered with the Log class. The Log class will still have a reference to it and hence, it will never be garbage collected. Moreover, since the class A has a reference to its ClassLoader in turn, the ClassLoader itself will never be garbage collected either, and so will none of the classes it loaded. This will lead to the permgen space error.



How to fix this:


Set –Xms(initial java heap size) and –Xmx(maximum java heap size)


-Xms512m -Xmx1024m -XX:PermSize=1024m -XX:MaxPermSize=2048m