facebook

How load EAR/resources/castor-mapping.xml frm within EJB/WAR

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #241288 Reply

    Hi All.

    I am trying to use the Castor XML Framework to read Objects from XML and write Objects to XML files.

    * I have castor-mapping.xml & castor.properties files bundled in the EAR at EAR/resources/castor-mapping.xml & EAR/resources/castor.properties
    * I have Class-path: resources/ in the META-INF/MANIFEST.MF files of both my EJB jar and WebApp war files.

    Using a regular EAR copy deployment to JBoss 4.0.1sp1, I am trying to access the castor-mapping.xml file from within one of the WebApp classes as follows:

    Marshaller marshaller = new Marshaller( new PrintWriter( System.out) );
    Mapping castorMapping = new Mapping();
    castorMapping.loadMapping( “/resources/castor-mapping.xml” );
    marshaller.setMapping( castorMapping );
    Marshaller.marshal( result, new PrintWriter( System.out) );

    the line castorMapping.loadMapping( “/resources/castor-mapping.xml” ); throws IOException: File Not Found

    I tried all combinations of “/resources/castor-mapping.xml”, “resources/castor-mapping.xml”, “castor-mapping.xml”, “/castor-mapping.xml” but nothing works!

    Any clues? Also, how can I get the above to work in case of MyEclipse *exploded* deployment where I don’t see the MANIFEST.MF anywhere in the exploded filesystem!!

    Thanks in advance,
    Sandeep Khanna

    #241321 Reply

    Riyad Kalla
    Member

    Any clues? Also, how can I get the above to work in case of MyEclipse *exploded* deployment where I don’t see the MANIFEST.MF anywhere in the exploded filesystem!!

    Did you create the META-INF directories under the root of your /src dir for both the EJB and Web proejcts?

    #241327 Reply

    @support-rkalla wrote:

    Any clues? Also, how can I get the above to work in case of MyEclipse *exploded* deployment where I don’t see the MANIFEST.MF anywhere in the exploded filesystem!!

    Did you create the META-INF directories under the root of your /src dir for both the EJB and Web proejcts?

    I had the the META-INF folder for the EJB project as EJB/source/META-INF with the following contents:
    -rw-r–r– 1 sandeepk sandeepk 407723 Nov 11 13:58 ejb-jar.xml
    -rw-r–r– 1 sandeepk sandeepk 66348 Nov 11 13:58 ibm-ejb-jar-bnd.xmi
    -rw-r–r– 1 sandeepk sandeepk 35116 Nov 11 13:58 ibm-ejb-jar-ext.xmi
    -rw-r–r– 1 sandeepk sandeepk 30086 Nov 11 13:58 jboss.xml
    -rw-r–r– 1 sandeepk sandeepk 31890 Nov 11 13:58 weblogic-ejb-jar.xml

    I added the Ant generated MANIFEST.MF file in here.

    I just created the META-INF folder for the WebApp project as WebApp/source/META-INF with empty contents. The WebApp source folder contains the Java source files. The WebApp/jsp. And, since in the exploded deployment, the WebApp/jsp folder contents show up I think it should be WebApp/jsp/META-INF

    I added the Ant generated MANIFEST.MF file in here.

    I already got the above requirement working with a typical EAR file deployment. I had to do the following to load a resource in the global (EAR file) classpath:

    Marshaller marshaller = new Marshaller( new PrintWriter( System.out) );
    Mapping castorMapping = new Mapping();
    InputSource inputSource = new InputSource( getClass().getResourceAsStream( “/castor-mapping.xml” ) );
    if( null != inputSource ){
    castorMapping.loadMapping( inputSource );
    marshaller.setMapping( castorMapping );
    marshaller.marshal( result );

    I think it’s working now except Castor is not able to load it’s castor.properties file from the EAR/resources/castor.properties location which causes my Castor specific customizations (pretty-print XML) to not load up. But, since I load the EAR/resources/castor-mapping.xml explicity atleast the Castor Mapping class loads that. So, Is there some global location *within* the Enterprise application where I can put castor.properties for it to be available to Castor?

    Hope the above EAR Classloader resource loading snippet helps someone.

    #241329 Reply

    @sandeepkhanna wrote:

    @support-rkalla wrote:

    Any clues? Also, how can I get the above to work in case of MyEclipse *exploded* deployment where I don’t see the MANIFEST.MF anywhere in the exploded filesystem!!

    Did you create the META-INF directories under the root of your /src dir for both the EJB and Web proejcts?

    I had the the META-INF folder for the EJB project as EJB/source/META-INF with the following contents:
    -rw-r–r– 1 sandeepk sandeepk 407723 Nov 11 13:58 ejb-jar.xml
    -rw-r–r– 1 sandeepk sandeepk 66348 Nov 11 13:58 ibm-ejb-jar-bnd.xmi
    -rw-r–r– 1 sandeepk sandeepk 35116 Nov 11 13:58 ibm-ejb-jar-ext.xmi
    -rw-r–r– 1 sandeepk sandeepk 30086 Nov 11 13:58 jboss.xml
    -rw-r–r– 1 sandeepk sandeepk 31890 Nov 11 13:58 weblogic-ejb-jar.xml

    I added the Ant generated MANIFEST.MF file in here.

    I just created the META-INF folder for the WebApp project as WebApp/source/META-INF with empty contents. The WebApp source folder contains the Java source files. The WebApp/jsp. And, since in the exploded deployment, the WebApp/jsp folder contents show up I think it should be WebApp/jsp/META-INF

    I added the Ant generated MANIFEST.MF file in here.

    I already got the above requirement working with a typical EAR file deployment. I had to do the following to load a resource in the global (EAR file) classpath:

    Marshaller marshaller = new Marshaller( new PrintWriter( System.out) );
    Mapping castorMapping = new Mapping();
    InputSource inputSource = new InputSource( getClass().getResourceAsStream( “/castor-mapping.xml” ) );
    if( null != inputSource ){
    castorMapping.loadMapping( inputSource );
    marshaller.setMapping( castorMapping );
    marshaller.marshal( result );

    I think it’s working now except Castor is not able to load it’s castor.properties file from the EAR/resources/castor.properties location which causes my Castor specific customizations (pretty-print XML) to not load up. But, since I load the EAR/resources/castor-mapping.xml explicity atleast the Castor Mapping class loads that. So, Is there some global location *within* the Enterprise application where I can put castor.properties for it to be available to Castor?

    Hope the above EAR Classloader resource loading snippet helps someone.

    Replying to my own posting.. hee hee…

    I just placed castor.properties in the EJB/source/ folder which already had hibernate.properties, log4j.properties, etc. And, Castor can now pretty-print XML to the console.

    #241337 Reply

    Riyad Kalla
    Member

    Are things working for you now?

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: How load EAR/resources/castor-mapping.xml frm within EJB/WAR

You must be logged in to post in the forum log in