Tech

20130213

Managing The CLASSPATH

The classpath in java and during Runtime, searches for classes and other zip type resources files to load into JVM memory to make the program run. classpath simply maps locations of classes to be use (load) as needed during application's life cycle; There's different ways of setting a java classpath:

  • Use the -classpath or -cp to set your classpath;
  • Use environment commands to set the classpath;
  • Using the class-path tag, on the application's manifest;

Examples:
  1. sdktool -[classpath,cp] class1[;|:]class2
    * ';' is use for Windows, ':' Unix like. sdktool is java, javac, jhat, etc..
  2. set classpath="class1;class2"

You can only add the following file types '.jar', '.zip' or '.class' into a classpath; Directories or the wildcard '*' can be used to add resources that eventually will be mapped during runtime. Compress files like '.jar' and '.zip' must contains '.class' files, other wise will be ignored.
While using the wildcard '*', the order of files loaded to the JVM vary from platform to platform and also from moment to moment on the same HW machine. Supposedly a well build application does not actually depend on a particular order, but if needed you must explicitly order files into the classpath. In which reads from left to write, and the first file is the one that will be use in case of similar jars with same full class name.
Classpath also can be set on the application's Manifest, using the class-path tag, but this tag does not honour the wildcard. While setting directories, java will load files in the order they appear in the path variables;

WLS

Uses delegation model when loading class, and to improve performance do the following steps:
  1. Checks its class load cache (to improve performance);
  2. While loading, search for the parent class; therefore goes reading from top to bottom on the family tree of the class, in case does not find the parent it does not attempt to load the class;
  3. If both child and parent exist, the parent is loaded first;

Weblogic comes with some feature such as hot-deployment and hot-redeployment. Allows to deploy and changes to newer versions of application module while server is running state, in which helps on avoiding downtime. On the java classloather do not support any standard for hot-deployment nor hot-redeployment; In this case you would need to restart the entire server in case of adding new libs or modifying your application.
Each application deployed on Weblogic Server has a separate hierarchy of classloaders from the system classloader; Also with the bool prefer-web-inf-classes child of container-descriptor tag on the weblogic.xml allow applications to use different libs, base on versioning details description. This is very useful when installing thirdparty libs or upgrading them, by default this tag is set to false.
Ex:
<?xml version="1.0" encoding="UTF-8"?>

<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
  <container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    <prefer-application-packages>
      <package-name>javax.faces.*</package-name>
      <package-name>com.sun.faces.*</package-name>
      <package-name>com.bea.faces.*</package-name>
    </prefer-application-packages>

    <prefer-application-resources>
      <resource-name>javax.faces.*</resource-name>
      <resource-name>com.sun.faces.*</resource-name>
      <resource-name>com.bea.faces.*</resource-name>
      <resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
      </prefer-application-resources>
  </container-descriptor>
</weblogic-web-app>


  As you may notice you need to inform which packages or resource to be loaded, therefore we use the list prefer-application-packages and prefer-application-resources tags; There is no need to use both at the same time.   ref:

20130117

Fatal Error, no space left on device WLS

I have been changing linux distros and I've faced with an issue in which is simple to resolve but does not happen very often on Debian's distros. Currently I am using Fedora, to get more experience with RH like OS.

While building from scratch my environment, installing the WLS for testing purpose I have faced the following FE (Fatal Error, I call it fatality):



The fatality is clear text, during extraction there is no more space left; But where???

To find out on linux, just open an terminal and run the df command.

$df

On my bellow screenshot, my /tmp directory is almost full.



  • As you can see my /tmp is 2G and is 79% full. There is not enough space for a WLS installation which takes a lot tmp space... I believe is about 1.2G of space, and setting a small 2G tmp like I did is a bad business.
  • But why did I not have such issue using Debian distro? Well, a friend with more RH experience answered me: "Fedora does not clean tmp directory!!!" (Vaaapaaa, in your face response...)
  • Well, after watching over the tmp I came with a possible theory. OS are not responsible for cleaning up tmp, but the programs that use this directory is, and Debians distro just want to be nice with us. 


I have listed a few commands that might be useful for this type of situation:

1. From the ehow blog I found the following commands in which needs to be run as root: 
a. finds and delete any file older than 10 days:
#find /tmp -mtime +10 |xargs rm -f 
b. Delete all empty directory from tmp:
#find /tmp -type d | xargs rmdir

*you can modify this commands to delete needed files, but this is a bad thing because some running programs might be using files from tmp directory; So be advise to be careful with what you delete. 

2. This is more elegant solution in which there no risk. If you have notice I am running a java command, therefore we will use a java solution for this issue without having to delete any files from tmp directory. 
a. create a tmp directory at your home user directory:  
$mkdir tmp
$ls
/home/"YourUser"/tmp

b. run the WLS jar installer with the followind java flag:  
java -Djava.io.tmpdir=/home/"yourUser"/tmp -jar wls1035_generic.jar


Either solution will work but I would rather use the second one; The screen shot taken bellow was when testing the commands from ehow blog.





ref:  How to Clear TMP in Fedora