Programmatically specify file location within ear file

Hi guys,
I am deploying an ear file under weblogic 6.1 and in part of the code I need to parse an xml file however, I can't figure out how to specify the path to the file. Whatever I try I always get an exception telling me the file cannot be found. The file itself resides within WEB-INF in the applications jar file which itself resides within the ear.
I don't know how to specify the files location.
Please help!
Simon.

Hi Simon,
I'm not sure if this will help - but I have had similar problems and am happy to share my experiences with you and hope they help you. (my test were done on JRun 3.0 - but am sure the behavior under weblogic is similar)
I am not sure what method you are using for accessing your xml file and what the package structure of you apps is but I assume that you are either doing a
<code>
String fileName = "myFile.xml";
File f = new File(fileName);
or
URL u = this.getClass().getResource(fileName);
</code>
I found problems with both these methods when deploying as a web app. The first method places the file in
<code> {JRunPath}\servers\default </code>
directory (which it should as the spec by default creates the file in the users default directory)
and the second creates a URL that does not correctly map to the location (see my post http://forum.java.sun.com/thread.jsp?forum=136&thread=184500)
neither of these is suitable for deploying a webapp. The only way to locate the resource seems to be to use either
<code>
fileName = ServletContext.getRealPath(fileName);
or
URL url = ServletContext.getResource(fileName);
</code>
This does leave open this issue on how to pass the servlet context down to the specific class within your application that loads the xml - the uglier option is to pass the servlet context object right down to the class that loads the resource - the other option is to use some kind of a static initializer to make the servletcontext object globally available
hope this helps

Similar Messages

  • Reading Java files from a EAR file

    I want to read all Java files from a EAR file and from inner (inside EAR) EAR or WAR file with out unpacking.
    suppose "Demo.ear" contaions the following files:
    abc.java
    programs / a.java
    programs / b.java
    src / index.java
    src / com / myFolder / main.java
    src.war
    and suppose "src.war" again contains some java files inside differenet folders.
    The main problem is that i can read all java files from "Demo.ear" but unable to reading from "src.war" b'coz my program is using JarFile class constructor which needs a archive file path, So only top level archive having the path but not the inner archives.
    So, pls help me out to this problems
    Thanks in advance

    Maybe you can use java.util.zip.ZipInputStream to
    open the Ear and recursively to open the files in
    it; I'm not sure whether this will result in a full
    unpacking of the file in some temporary directory,
    though.
    Please let me know if it worked the way you wanted,
    I'm curious about it.This jerk just created the third thread about the same topic, because he didn't understand your suggestion, which I already provided earlier.
    http://forum.java.sun.com/thread.jspa?threadID=790015

  • I get ERROR U44M1P7: Error log file location: C:\Program Files (x86)\Common Files\Adobe\Installers

    When updating Photoshop CS6 (Creative Cloud) I get ERROR U44M1P7: Error log file location: C:\Program Files (x86)\Common Files\Adobe\Installers. Initial Installation and actual funcioning wuith no problem, only on updating. I have tried several times with same error.

    Hi Alberto Pomares,
    Please refer the KB Doc : http://helpx.adobe.com/creative-suite/kb/error-u44m1p7-installing-updates-ccm.html

  • Java files from a EAR file and from inner (inside EAR)

    I want to read all Java files from a EAR file and from inner (inside EAR) EAR or WAR file with out unpacking.
    suppose "Demo.ear" contaions the following files:
    abc.java
    programs / a.java
    programs / b.java
    src / index.java
    src / com / myFolder / main.java
    src.war
    and suppose "src.war" again contains some java files inside differenet folders.
    The main problem is that i can read all java files from "Demo.ear" but unable to reading from "src.war" b'coz my program is using JarFile class constructor which needs a archive file path, So only top level archive having the path but not the inner archives.
    So, pls help me out to this problems
    Thanks in advance

    Firstly Sorry to writing long letter. but i was unable to express my problem.
    see my code==============================
    JarFile jarFile = new JarFile("Demo.ear");
    Enumeration e=jarFile.entries();
    while (e.hasMoreElements())
    JarEntry entry=(JarEntry)e.nextElement();
    if (entry.getName().endsWith(".war"))
    // Then what Next to do...........
    ===========================================
    you have mentioned "theFile" , What is this?...............
    InputStream in = theFile.getInputStream(theEntryOfTheWAR);
    This line is not a compatible type casting in Java..........
    ZipOutputStream theWar = new ZipInputStream(in);

  • Java files from a EAR file

    I want to read all Java files from a EAR file and from inner (inside EAR) EAR or WAR file with out unpacking.
    suppose "Demo.ear" contaions the following files:
    abc.java
    programs / a.java
    programs / b.java
    src / index.java
    src / com / myFolder / main.java
    src.war
    and suppose "src.war" again contains some java files inside differenet folders.
    The main problem is that i can read all java files from "Demo.ear" but unable to reading from "src.war" b'coz my program is using JarFile class constructor which needs a archive file path, So only top level archive having the path but not the inner archives.
    So, pls help me out to this problems
    Thanks in advance

    please help me
    I am waiting for ur response
    thanking you

  • Locate resources within ear file

    Hi,
    I have a web app contained within an ear file. I am trying to locate resources from with in a class using getClass().getClassLoader().getResource() and getResourceAsStream() without any luck. From within a servlet, I am using a call to getServletContext().getRealPath() successfully.
    Anything other than a servlet is throwing a NullPointerException. I am trying to load images and an xml config file to generate images on dynamically. The files are all located within the web app.
    Any thoughts? Thanks in advance.

    You can move them to a "library" container on the EAR level and specify the location in the orion-application.xml. Assuming you've created a "lib" directory to store libraries in, you would get something like:
      <library path="lib" />
      ...If it is redundancy you're trying to resolve, this is the way to go. Although, simply placing everything that is needed by either web or ejb module in a application wide library directory is something you might not want to do. Stick to WEB-INF/lib if libraries only are used by the web module.

  • /lib directory within EAR file

    I have an EAR file that contains several WAR files. I would like to remove the 'WEB-INF/lib' directory from the individual WAR files and place it in the parent EAR file, in the interest of avoiding redundancy and reducing file size. What's the best way to do this?
    Thanks,
    jeff

    You can move them to a "library" container on the EAR level and specify the location in the orion-application.xml. Assuming you've created a "lib" directory to store libraries in, you would get something like:
      <library path="lib" />
      ...If it is redundancy you're trying to resolve, this is the way to go. Although, simply placing everything that is needed by either web or ejb module in a application wide library directory is something you might not want to do. Stick to WEB-INF/lib if libraries only are used by the web module.

  • Packaging - putting support files within ear file

    We have a J2EE application that leverages some xml control files. We would like to package the application with these support files all within the ear file. Currently, these files get moved seperate from the ear, which causes files to be missed sometimes during deployment. Our questions are as follows:
    1) Can these files be placed in the ear file?
    2) How do we reference them? Currently the application works by specifying the path to these files in the web.xml, what is the path we should use so that our application can find the files?

    "Brandon Witte" <[email protected]> skrev i en meddelelse
    news:[email protected]..
    We have a J2EE application that leverages some xml control files. Wewould like to package the application with these support files all within
    the ear file. Currently, these files get moved seperate from the ear, which
    causes files to be missed sometimes during deployment. Our questions are as
    follows:
    >
    1) Can these files be placed in the ear file?
    2) How do we reference them? Currently the application works byspecifying the path to these files in the web.xml, what is the path we
    should use so that our application can find the files?
    The simplest solution would be to put them in the WEB-INF/classes or
    APP-INF/classes directories and load them through the classloader.

  • Class not found in web-inf/classes folder of war file within ear file

    Hi all,
              I am using Weblogic 8.1 sp4. I have a war file within an ear file. I am trying to deploy the war file with a few classes within its web-inf/classes folder, however when the classes are in that folder I consistently get a class not found exception when trying to instantiate them. If I package the classes in a jar file and then put that jar file within the web-inf/lib folder of the war, the classes are also not found.
              If I put these two classes in the app-inf/classes folder of the ear file, everything works as expected and the classes are found.
              Any ideas of why this is happening. This seems to be a very simple thing that should work, but appears to not be working at all.
              thanks in advance for any suggestions or ideas.

    Hi,
              This is a known limitation/issue with WL. There is also no way around this.
              Regards,
              LG

  • Specifying Schema Location in XML file and not in the Java code

    I have a repository of schema xsd files. When I receive my xml file, I need to validate it against the specified schema. The xml file would declare the schema location, using the following syntax:
    <CERD:CERD xsi:schemaLocation = "..\CERD.xsd" xmlns:CERD = "CERD.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
    Is it really necessary to define the schema location again in the JAVA code? Why set the schemaLocation in the xml file at all then?
    Does anybody have any examples where the schema location is not set in the JAVA code? I am using Java 1.6, and at this point in time I only need to validate. Any help would be appreciated.

    Thank you very much for your quick reply. I have made some progress but I am still stumped.
    In my code I am doing this:
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = factory.newSchema();
    Validator validator = schema.newValidator();
    validator.validate(XML_SOURCE);
    I find this works if my schema does not have a target namespace. I have downloaded the following simple example from the internet that uses a target namespace and it fails:
    library1.xsd:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.org/prod"
    xmlns:prod="http://example.org/prod">
    <xsd:element name="product" type="prod:ProductType"/>
    <xsd:complexType name="ProductType">
    <xsd:sequence>
    <xsd:element name="number" type="xsd:integer"/>
    <xsd:element name="size" type="prod:SizeType"/>
    </xsd:sequence>
    <xsd:attribute name="effDate" type="xsd:date"/>
    </xsd:complexType>
    <xsd:simpleType name="SizeType">
    <xsd:restriction base="xsd:integer">
    <xsd:minInclusive value="2"/>
    <xsd:maxInclusive value="18"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>
    <prod:product xmlns:prod="http://example.org/prod"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="library1.xsd"
    effDate="2001-04-02">
    <number>557</number>
    <size>10</size>
    </prod:product>
    I get the following SAXParseException when I validate:
    [line 4, col 36|
    cvc-elt.1: Cannot find the declaration of element 'prod:product'.
    Am I doing something wrong with the namespace declaration?
    Edited by: alfredamorrissey on Oct 31, 2007 6:34 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Specify a property file inside a ear file

    Hi guys I have this myApplication.ear file.
    All the project inside the ear file are using myProperties.properties file.
    I have been told that this property file has to be inside the ear file.In websphere 7.0 ,the administrator will specify a jvm classpath like /webAS/installedApps/myApplication.ear/myProperties.properties.During runtime my code will find the property file using this class path
    I am using RAD 7.5 to generate the ear file.Can some one tell me how to achieve this.Basically my ear file has to be bundled with the property file.
    thanks
    m

    You might get better results from a RAD forum if you a havent already figured out your issue.

  • How to change web-app display name within EAR file?

    Currently we are deploying an EAR file (which contains a web-app and an EJB) per
    BEA recommendations. The web-app shows up on the admin console with '/' as the
    name. Is there anyway to change this to the name I want?
    thx,
    Matt

    FYI - here is the entire content of applicaiton.xml in the EAR file we deploy:
    <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application
    1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
    <application>
    <display-name>RVApp</display-name>
    <module>
    <ejb>RVTrackingBean</ejb>
    </module>
    <module>
    <web>
    <web-uri>RVWebApp</web-uri>
    <context-root>/</context-root>
    </web>
    </module>
    </application>
    "Erik Johnson" <[email protected]> wrote:
    >
    No, you can't change that in the console. It's defined in the application's
    application.xml
    descriptor file.
    erik
    "Matt Savino" <[email protected]> wrote:
    Currently we are deploying an EAR file (which contains a web-app and
    an EJB) per
    BEA recommendations. The web-app shows up on the admin console with'/'
    as the
    name. Is there anyway to change this to the name I want?
    thx,
    Matt

  • ClassNotFoundException trying to load classes in a .war file inside an .ear file

    Hi. I've deployed an EJB2 enterprise app as an ear file on WebLogic 6
              without errors. The ear file contains web app and ejb components in war and
              jar files. The web component is set to be the default web app in the
              config.xml file. Everything deploys without error messages.
              My problem is that I get ClassNotFoundExceptions when I try to invoke a
              servlet (via its servlet-mapping) or do Class.forName() on any class file in
              the war file.
              I see in '.wl_temp_do_not_delete' that the ear file has been decomposed into
              the ejb jar and web war files. The war file is not 'exploded' into a
              directory structure, however (as the console.war is). Is this an error
              (should the class packages in the war file be 'exploded'?)
              I don't see a tag in the web.xml, config.xml, or application.xml that tells
              the server to explode the war file--is there one?
              Note that if I manually copy the exploded class folders into the
              '_tmp_war_myserver_myserver_<<webappname>>' directory (and not, curiously,
              into a WEB-INF/classes subdirectory of that directory), the servlets and
              other classes load correctly. Also, jsps and html files load just fine
              without exploding the war file.
              Note also that the server complains about not being able to find the
              classes, even though it reports that the decomposed war file is in the
              classpath. Is there a problem loading class files from a .war file (because
              the namespace is different, with root classes located in WEB-INF/classes
              rather than the .war file's root?)
              Also, in the application.xml file, what is the meaning of the
              <context-root></context-root> element? What should its value be? What if
              you leave it blank?
              Thanks for any help,
              Reid
              

    Is there a way to add jar libraries to the Oracle JVM CLASSPATH? Is this the same as the system's CLASSPATH env. variable?
    Thank you!
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Alex McClennan ([email protected]):
    The package prefix in the code extract was correct - i.e. "oracle.aurora.jndi". A value of "oracle.aurora.jndi.*" would be incorrect.
    The problem is that the context factory implementation specified (com.evermind.server.ApplicationClientInitialContextFactory
    ) can't be found, the mostly likely reason being that the library containing the class isn't on the classpath.
    Cheers,
    ax<HR></BLOCKQUOTE>
    null

  • How to access images files outside an ear file

    I tried accessing images that are not part of the ear file which i deployed. And
    which created on a fly during the execution of applicaiton. I get URL not found
    error, can any one let me know if is there any way where in i could access the
    files not part of deployed ear. I am uisnig Weblogic 6.1 Awaiting for a reply
    ASAP.
    Thanks
    Anastasia

    Generally, accessing files that are not within your
              war hierarchy is not allowed. Everything the webapp
              needs should be contained within the webapp.
              WebLogic does have an extension known as "virtual
              directories" which does allow you to access content
              outside the war. There is information on it at:
              http://e-docs.bea.com/wls/docs70/ConsoleHelp/war_webappext_virtualdirectorymapping_config.html
              mark
              > "Ajit Mukka" <[email protected]> wrote in message
              > news:[email protected]..
              >
              > Hi
              >
              > I tried accessing files that are part of my Default WebApp directory.
              > These files are not part of the ear file which i deployed. I create
              > few runtime files and make dynamic calls to access those files.
              > I get URL not found error, can any one let me know if is there any
              > way wherein i could access the files not part of deployed ear.
              > awaiting for a reply asap.
              >
              > Thanks
              > Ajit
              >
              

  • Dynamic Template file location in control file in Bursting

    HI,
    Normally we hard code the location of the template in the control file and keep the file at that server location.
    When we move from DEV to higher instances, we might need to change this path in control file. Is there any way to handle this dynamically and it will take similar path from the instance to which this control file is deployed.
    I need the syntax to handle this situation.
    Thanks,
    Praveen

    <FONT FACE="verdana" SIZE="2">
    You have to hardcode the values like the one below. In this case, even if you clone your instance, it will continue to work.
    <xapi:template type="rtf" location="xdo://SQLAP.XXV8_APXPBSRA.en.US/?getSource=true"
    ${short_appl_name} = SQLAP
    ${template_code} = XXV8_APXPBSRA
    Darshan Says,
    In this case assuming that while registering template you have specified langugae as 'English' and territory as 'United States', if you have not specified any territory then replace US with 00 for default.
    References:-
    http://garethroberts.blogspot.com/2008/03/bi-publisher-ebs-bursting-101.html
    Having Trouble using template in control file

Maybe you are looking for