0 Replies Latest reply on Apr 12, 2006 6:01 PM by Jim Jarrett

    EAR files, Property file locations within, JBOSS and WebLogi

    Jim Jarrett Newbie

      I am trying to evaluate what it would take to move an existing app from WebLogic 8.1 to JBoss.

      I am trying to get our app to initialize, and it's failing with FileNotFound exceptions when trying to read property files stored in the EAR.

      I've distilled things down to a very simple example to illustrate the problem.

      I started with a very simple EAR that implemented a stateless session bean. My EJB deploys, and I wrote a simple client app that sucessfully calls it. So all of the deployment descriptors and InitialContext stuff works. I actually used the MyEclipse plugin to create this enterprise project and deploy this to both JBoss and WL.

      Now, I need the path to a properties file (because as I scale this up, I need that file name to initialize a Quartz StdSchedulerFactory). I took code from our WebLogic deployed EJB and tried it in JBoss, but I get the FileNotFound exceptions I described above.

      Thing is, they go away if I deploy my EAR as an exploded EAR. This won't fly for real, I want to deploy packaged.

      Anyways - here what I get:

      For an EAR packaged like so:

      C:\jboss-4.0.2\server\default\deploy>jar xvf AdviceEAR.ear
      extracted: advice.jar
      extracted: APP-INF/classes/dao.properties
      extracted: META-INF/MANIFEST.MF
      extracted: META-INF/application.xml

      This code works if deployed as an exploded EAR:

       public String getAdvice() {
       System.out.println("in getAdvice");
      
       InputStream daoProperties = getClass().getClassLoader().getResourceAsStream("APP-INF/classes/dao.properties");
       Properties properties = new Properties();
       try {
       properties.load(daoProperties);
       if (properties != null) {
       for (Iterator it = properties.entrySet().iterator(); it.hasNext();) {
       Map.Entry entry = (Map.Entry) it.next();
       String value = null;
       String key = null;
       try {
       key = (String) entry.getKey();
       value = (String) entry.getValue();
       } catch (Throwable e) {
       System.out.println("Invalid dao property for key [" + key + ", " + entry.getValue() + "] " + e);
       }
      
       System.out.println("Key: " + key + " Value: " +value);
       }
       }
      
       } catch (Throwable e) {
       System.out.println("Failed to load dao properties file");
       }
      
       URL daoPropsURL = getClass().getClassLoader().getResource("APP-INF/classes/dao.properties");
      
       if (daoPropsURL != null) {
       String daoPropsPath = daoPropsURL.getPath();
      
       if (daoPropsPath != null) {
       System.out.println("daoPropsPath is " + daoPropsPath);
       }
       else {
       System.out.println("daoPropsPath is null!");
       }
      
       String daoPropsFile = daoPropsURL.getFile();
      
       if (daoPropsFile != null) {
       System.out.println("daoPropsFile is " + daoPropsFile);
       }
       else {
       System.out.println("daoPropsFile is null!");
       }
      
       }
       else {
       System.out.println("daoPropsURL is null");
       }
      
      
       Properties urlProperties = new Properties();
       try {
       FileInputStream is = new FileInputStream(daoPropsURL.getFile());
       urlProperties.load(is);
       } catch (Throwable e) {
       System.out.println("Failed to load dao properties file: " + e.getMessage());
       }
      
       if (urlProperties != null) {
       for (Iterator it = urlProperties.entrySet().iterator(); it.hasNext();) {
       Map.Entry entry = (Map.Entry) it.next();
       String value = null;
       String key = null;
       try {
       key = (String) entry.getKey();
       value = (String) entry.getValue();
       } catch (Throwable e) {
       System.out.println("Invalid dao property for key [" + key + ", " + entry.getValue() + "] " + e);
       }
      
       System.out.println("Key: " + key + " Value: " +value);
       }
      
       }
       int random = (int) (Math.random() * adviceStrings.length);
       return adviceStrings[random];
       }
      


      The result:

      16:41:55,878 INFO [STDOUT] in getAdvice
      16:41:55,898 INFO [STDOUT] Key: property4 Value: D
      16:41:55,898 INFO [STDOUT] Key: property3 Value: C
      16:41:55,898 INFO [STDOUT] Key: property2 Value: B
      16:41:55,898 INFO [STDOUT] Key: property1 Value: A
      16:41:55,898 INFO [STDOUT] daoPropsPath is /C:/jboss-4.0.2/server/default/deploy/AdviceEAR.ear/APP-INF/classes/dao.properties
      16:41:55,898 INFO [STDOUT] daoPropsFile is /C:/jboss-4.0.2/server/default/deploy/AdviceEAR.ear/APP-INF/classes/dao.properties
      16:41:55,898 INFO [STDOUT] Key: property4 Value: D
      16:41:55,908 INFO [STDOUT] Key: property3 Value: C
      16:41:55,908 INFO [STDOUT] Key: property2 Value: B
      16:41:55,908 INFO [STDOUT] Key: property1 Value: A
      


      But deployed as a packaged app, I get:

      16:42:50,626 INFO [STDOUT] in getAdvice
      16:42:50,626 INFO [STDOUT] Key: property4 Value: D
      16:42:50,626 INFO [STDOUT] Key: property3 Value: C
      16:42:50,626 INFO [STDOUT] Key: property2 Value: B
      16:42:50,626 INFO [STDOUT] Key: property1 Value: A
      16:42:50,626 INFO [STDOUT] daoPropsPath is file:/C:/jboss-4.0.2/server/default/tmp/deploy/tmp29671AdviceEAR.ear!/APP-INF/classes/dao.properties
      16:42:50,626 INFO [STDOUT] daoPropsFile is file:/C:/jboss-4.0.2/server/default/tmp/deploy/tmp29671AdviceEAR.ear!/APP-INF/classes/dao.properties
      16:42:50,646 INFO [STDOUT] Failed to load dao properties file: file:\C:\jboss-4.0.2\server\default\tmp\deploy\tmp29671AdviceEAR.ear!\APP-INF\classes\dao.properties (The filename, directory name, or volume label syntax is incorrect)
      


      Why? It works fine both ways in WebLogic. That exclamation point in the path and file name when calling getResource() obviously look suspicious. What am I doing wrong?