简体   繁体   中英

DeploymentException & Class Not Found on WebLogic Admin Server 11g

Related: Load external properties files into EJB 3 app running on WebLogic 11

Using Oracle Enterprise Pack for Eclipse, I created an Enterprise Project and named it:

PropertiesDemoEAR

Also created a PropertiesDemoEARWeb module in which I put this code

(inside PropertiesDemoEARWeb / Java Resources / src / com.project.util):

package com.project.util;

public class PropertiesFileHandler extends ApplicationLifecycleListener {

     private static final String FILE = "C:/etc/error.properties";

     public void preStart(ApplicationLifecycleEvent evt) {
        System.out.println("\n\n\t\tInside preStart() method\n\n");
        InputStream is = 
        evt.getApplicationContext().getAppClassLoader().getResourceAsStream(FILE);
        try {
            Properties convertedProps = 
                       convertStreamToProperties(is);
            String userMissingError =
                   convertedProps.getProperty("USER_MISSING_ERROR");
            System.out.println("\n\n\t\tuserMissingError = " 
            + userMissingError + "\n\n");
        } catch (Throwable e) {
             e.printStackTrace();
        }
     }

     public Properties convertStreamToProperties(InputStream is) throws IOException {
        System.out.println("\n\n\t\tInside convertStreamToProperties() method\n\n");
        Properties props = new Properties();
        if (is == null) {
          throw new FileNotFoundException("property file '" + FILE + "' not found");
        } else {
          props.load(is);
          return props;
        }
     }

 }

Inside PropertiesDemoEAR/EarContent/META-INF/weblogic-application.xml

I added the following listener declaratively:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application 
         xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" >
    <!--weblogic-version:10.3.5-->
    <wls:application-param>
        <wls:param-name>webapp.encoding.default</wls:param-name>
        <wls:param-value>UTF-8</wls:param-value>
    </wls:application-param>

    <wls:listener>              
         <wls:listener-class>
         com.project.util.PropertiesFileHandler
         </wls:listener-class>
    </wls:listener>
</wls:weblogic-application>

Right clicked on the PropertiesDemoEAR / Export / EAR file / Destination:

C:\Oracle\Middleware\user_projects\domains\MyDomain\autodeploy

When I run WebLogic 11g through Eclipse, I get this error message in the console:

 [ERROR] AdapterManager - ServletContainerAdapter manager not initialized correctly.
 <oracle.tip.adapter.apps.AppsConnectionFactory> 
 ConnectionManager cm: weblogic.connector.outbound.ConnectionManagerImpl@12433e7-eis/Apps/Apps        
 ManagedConnectionFactory mcf:   
 oracle.tip.adapter.apps.AppsManagedConnectionFactory@4303022b
 <Jun 30, 2011 5:50:24 PM PDT> <Error> <Deployer> <BEA-149265> 
 <Failure occurred in the execution of deployment request 
  with ID '1309481424487' for task '0'. Error is:   
  'weblogic.management.DeploymentException: '
   weblogic.management.DeploymentException: at
   weblogic.application.internal.flow.
   BaseLifecycleFlow$CreateListenerAction.run(BaseLifecycleFlow.java:176) at
   weblogic.security.acl.internal.
   AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at 
   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at
   weblogic.application.internal.flow.
   BaseLifecycleFlow$BaseAction.invoke(BaseLifecycleFlow.java:104) at   
   weblogic.application.internal.
   flow.HeadLifecycleFlow.createListener(HeadLifecycleFlow.java:117)
   Truncated. see log file for complete stacktrace

   Caused By: java.lang.ClassNotFoundException: 

   com.project.util.PropertiesFileHandler 

   at weblogic.utils.classloaders.
   GenericClassLoader.findLocalClass(GenericClassLoader.java:297)

Question(s):

(1) What am I possibly doing wrong? Why can't it find my PropertiesFileHandler class?

(2) Is the location (c:/etc/error.properties) of my properties file suitable or should it be inside MyDomain directory?

(3) Is there a default directory or just simple configuration area that WebLogic loads properties files which are accessible to any application that runs in WebLogic?

Try making sure that the class is in the /lib folder for the machine where the application is being deployed.

Got it working... The issue was that I had it set up as Web Project rather than a Java EE Utility Project in Oracle Enterprise Edition for Eclipse.

As a web project, it was putting.class files inside WEB-INF/classes instead of APP-INF.

Also, needed to put error.properties inside my actual domain.

C:\Oracle\Middleware\user_projects\domains\MyDomain

In regards to my own question:

Is there a default directory or just simple configuration area that WebLogic loads properties files which are accessible to any application that runs in WebLogic?

If -Dweblogic.ext.dirs is not set, it defaults to $DOMAIN/lib;$WL_HOME/common/lib/ext;$WL_HOME/server/lib/ext

So if you store error.properties in $DOMAIN/lib it will be on the CLASSPATH and you should be able to load it using getResourceAsStream("error.properties")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM