Pages

Tuesday, January 13, 2015

Accessing Context Root Programatically


There are several needs to access context root in various places of your application.

Various ways are,

In Jspx${pageContext.request.contextPath}

In servlet:
    public static String getContextpath(HttpServletRequest request) {
        return request != null ? request.getContextPath() : null;
    }

In bean:
   public static String getContextpath() {
        ExternalContext extContext= FacesContext.getCurrentInstance().getExternalContext();
        String url = extContext.getRequestContextPath();
        return url;
    }

In Javascript:
function getContextPath(){
            return window.location.pathname.substring(0,window.location.pathname.indexOf("/",2));
            }

In CSSbackground: url(../resources/images/header.jpg")

Wednesday, January 7, 2015

Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/Server


Few weeks back, My JdeveloperR2 set up got corrupted.Best way to clean up and install it again.For some reasons i dint clean up my entire stuff.


With Existing Config. I start installing JdeveloperR2.During weblogic server start up.I caught this exception.

Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/Server
Caused by: java.lang.ClassNotFoundException: weblogic.Server
     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:247) 


After few readings, I came to know class path is not mapped properly.Even though I mapped properly, repeatably got this exception.


Later, I Noticed some mapping where not right in setDomainEnv.sh File. Mappings in setDomainEnv.sh referring to my corrupted set up.

Finally, Resolved by this way,


Go to the location: C:\Users\xxxx\AppData\Roaming\JDeveloper\system11.1.2.4.39.64.36.1\DefaultDomain\bin\setDomainEnv.sh

set COMMON_COMPONENTS_HOME=F:\Oracle\Middleware\oracle_common
set WC_ORACLE_HOME=F:\Oracle\Middleware\jdeveloper
set PORTLET_ORACLE_HOME=F:\Oracle\Middleware\jdeveloper
set WC_ORACLE_HOME=F:\Oracle\Middleware\jdeveloper
set WL_HOME=F:\Oracle\Middleware\wlserver_10.3

set SUN_JAVA_HOME=F:\Oracle\Middleware\jdk160_24

Note :Please ensure that these mappings where pointed to correct specified location in your .sh file. 
if they were right, class path is actual problem.

After rectifying this Exception, Then I can run my startWebLogic.sh.

Now Works Fine.