Regarding reading a jar/war file

Hi,
I have to read a war file. below is the code...
String Name;
Name="D://work//webapp//meta-inf//MANIFEST.MF";
InputStream is= null;
JarInputStream jis = null;
is = Class1.class.getClassLoader().getResourceAsStream(Name);
if (getClass().getClassLoader() == null)
is = ClassLoader.getSystemClassLoader().getSystemResourceAsStream( Name );
jis = new JarInputStream(is );
but the InputStream is as value as null, and nullpointerexception is returned.
Any help would be great.
Thanks

user10196088 wrote:
String Name;
Name="D://work//webapp//meta-inf//MANIFEST.MF";For one, you don't need the double slashes when they're that way. A single slash would be enough.
InputStream is= null;
JarInputStream jis = null;
is = Class1.class.getClassLoader().getResourceAsStream(Name);That's not how getResourceAsStream() works. You're giving it a full filesystem path. Read through the Javadoc.
if (getClass().getClassLoader() == null)
is = ClassLoader.getSystemClassLoader().getSystemResourceAsStream( Name );
}Why are you reassigning the inputstream here again (still with the wrong Name too).
jis = new JarInputStream(is );Even if your faulty Name there did work, you'd expect a JarInputStream to read a manifest file? Which is not a jar file at all? The file extension .MF should've clued you to that already.
Any help would be great.Well, you're pretty much doing everything wrong. Syntactically and logically.
Also when posting code, put it between tags and it'll format nicely.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Using web resources in a JAR/WAR file in another project

    Hi,
    I would like to make a core set of .jspx files available to other developers without them having to physically include each of the .jspx files into their JDeveloper projects manually.
    I've tried creating various WAR and JAR files, and then including those into my JDeveloper projects (Project Properties > Libraries > Add Jar/Directory) but the result is always the same:
    javax.faces.FacesException: Problem in renderResponse: /test.jspx Not Found in ExternalContext as a Resource
    In the simplest case, I've created a war file with only a single file in it:
    /test.jspx
    I've also tried a war with:
    /public_html/test.jspx
    Can anybody provide some pointers as to what it is I need to do here? Some things I've read suggest that I need to extend the classpath to include my test.war, but I can't find the appropriate setting for this in JDeveloper.
    I'm using the latest version of JDeveloper 10g, and for the purposes of testing I'm using the embedded OC4J.
    Thanks for any tips!
    Alistair.

    I haven't done this so far, but it should be possible.
    One thing you should have in mind is this:
    Every WAR is a separate Web Application and has its own context as well as context root.
    If you'd like to reuse pages from another WAR file you need to know its context root at the bare minimum to reference to it.
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Regarding reading data from a file in the application server.

    Hello Everyone,
    My question is:
    The file in the application server consists of data with header, detail and trail out of which the detail contains the main information. The detail again contains the data in the form of a continuous string and again some spaces corresponding to a single record. I need to split the data in the internal table in such a way so that the first few characters get into field-1 of the target internal table. Again I need to consider the spaces for accessing the data for filling up in field-2. How do I decide on the 'Split' statement and specially when the whole string has to be taken care of as contatining data in a single string format without space and again some data after some spaces corresponding to a single record.
    Your help is very much needed. Thanks to all the experts in advance.

    Hi
      This is the sample code I was used for the similar requirement.
    DATA: single_line TYPE string .
    v_file_listings = pa_filn1.
    IF v_file_listings IS INITIAL .
    MESSAGE e039 WITH v_file_listings.
    ENDIF.
    *-- read file, split lines into fields and put data into table
    OPEN DATASET v_file_listings FOR INPUT IN TEXT MODE ENCODING NON-UNICODE. "Opening the files
    IF sy-subrc EQ 0.
    DO.
    READ DATASET v_file_listings INTO single_line. "Reading the content of file into line
    IF sy-subrc = 0.
    IF sy-index > 1. "skip header-line
    SPLIT "Split the content of line into work area
    single_line
    AT k_split
    INTO
    wa_listings-kschl " Condition type
    wa_listings-tabname16 " Condition table name
    wa_listings-vkorg " Sales organisation
    wa_listings-kunnr " sold-to party numberor ship-to party number
    wa_listings-matnr " Material Number
    wa_listings-kodatab " Valid-from date
    wa_listings-kodatb1. " Valid-to date
    APPEND wa_listings TO itab_listings. "Appending Work Area to internal table
    ENDIF.
    ELSE.
    EXIT.
    ENDIF.
    v_count1 = sy-tabix.
    ENDDO.
    Regards,
    Sreeram

  • Deploying MBean with ear/jar/war files

    Hi!
    I'm working on a project where we plan to use jmx to manage our web(servlet) application.
    I have created a simple test MBean, and try to create the MBean with MBeanServer.
    When i try this, i got a ReflectionException(ClassNotFoundException).
    I have try to deploy the MBean together with the war file(inside ear), create
    a jar file and put it into myserver classpath(web console)...
    Nothing works...
    Audun

    On 30 Aug 2001 05:17:27 -0800, Audun <[email protected]> wrote:
    >
    I'm working on a project where we plan to use jmx to manage our web(servlet) application.
    I have created a simple test MBean, and try to create the MBean with MBeanServer.
    When i try this, i got a ReflectionException(ClassNotFoundException).
    I have try to deploy the MBean together with the war file(inside ear), create
    a jar file and put it into myserver classpath(web console)...It seems like if you want the MBeanServer to instantiate the MBean,
    then you have to put the MBean classes in the server classpath. This
    is probably the best approach, if you want a centralized admin MBean
    to do management from the WLS admin server across a domain.
    If you want an MBean instance per managed server, then you can have
    your application (during initialization) instantiate the MBean and
    register it with the MBeanServer. This approach lets you package your
    MBean classes with your application ear/war/jar.
    You might want a combination of both approaches. An admin MBean
    manages across the domain, and an MBean on each managed server listens
    for attribute change notifications from the admin MBean to deal with
    propagating configuration changes to the application running across
    the cluster. Unfortunately, I have not found any examples or
    documentation on how to get MBean invocations and notifications to
    work remotely. (You know it's possible because the WLS MBeans do it!)
    <hack> <hack> <hack>
    Ben

  • Help needed regarding reading in a text file and tokenizing strings.

    Hello, I require help with a task I've been set, which asks me to read in a text file, and check the contents for errors. The text file contains lines as follows.
    surname:forename:1234:01-02-06
    I can read in the file, but dont know how to split the strings so each token can be tested (ie numbers in the name tokens)
    However, I am not allowed to use regex functions, only those found in java.io.*
    I think i should be putting the tokens into an array, but have had no luck so far in doing so. Any help would be appreciated.

    public class Validator {
         public static void main(String args[]) {
              String string = "Suname:Forename:1234:01_02-06";
              String stringArray[] = string.split(":");
              System.out.println (validateLetters(stringArray[0]));//returns true
              System.out.println (validateNumbers(stringArray[3]));//returns false
         static boolean validateLetters(String s) {
                 for(int i = 0; i < s.length(); i++) {
                 char c = s.charAt(i);
                 if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z')) {
                         return false; //return false if one of characters is other than a-z A-Z
                 }//end if
                 }//end for
                 return true;
         }//end validateLetters
         static boolean validateNumbers(String s) {
                 for(int i = 0; i < s.length(); i++) {
                 char c = s.charAt(i);
                 if ((c < '0' || c > '9') && (c != '-')) {
                         return false; //return false if one of characters is other than 0-9 or -
                 }//end if
                 }//end for
                 return true;
         }//end validateNumbers
    }

  • Can't read JSP from WAR file

              Hi, Everyone:
              The WAR really drives me crazy.
              everytime when i reach the jsp files in war, it throws exception:
              <I> <WebAppServletContext-skylos> Generated java file:
              C:\weblogic\myserver\_tmp_war\jsp_servlet\common\test.java
              <E> <WebAppServletContext-skylos> Servlet failed with Exception
              java.lang.NullPointerException
              at java.util.Hashtable.put(Hashtable.java:380)
              at weblogic.servlet.jsp.OneOffJspLoader.loadClass(JspStub.java:433)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
              i uses WLS5.1 SP6.
              my WAR is under /weblogic/myserver/ (i can load html from my war)
              thanks
              han
              

              i solved it.
              it is about relative path and absolute path.
              coz browser tries to search /common/checklogin.jsp
              from documentRoot.
              han
              "hansen" <[email protected]> wrote:
              >
              >i solved it.
              >
              >the reason is i didn't install SP6 correctly.
              >
              >but i got another question:
              >
              >everytime, i enter password and login name on login.jsp
              >page,and press "Login". it should call checkLogin.jsp. but
              >the browser asks me to "save it" or "open it".
              >
              >thanks
              >
              >han
              >
              >han
              >
              >
              >"hansen" <[email protected]> wrote:
              >>
              >>Hi, Everyone:
              >>
              >>The WAR really drives me crazy.
              >>
              >>everytime when i reach the jsp files in war, it throws exception:
              >>
              >><I> <WebAppServletContext-skylos> Generated java file:
              >>
              >> C:\weblogic\myserver\_tmp_war\jsp_servlet\common\test.java
              >>
              >><E> <WebAppServletContext-skylos> Servlet failed with Exception
              >>
              >>java.lang.NullPointerException
              >>
              >> at java.util.Hashtable.put(Hashtable.java:380)
              >>
              >> at weblogic.servlet.jsp.OneOffJspLoader.loadClass(JspStub.java:433)
              >>
              >> at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
              >>
              >>i uses WLS5.1 SP6.
              >>
              >>my WAR is under /weblogic/myserver/ (i can load html from my war)
              >>
              >>thanks
              >>
              >>han
              >
              

  • Replication of utility/helper classes in JAR/WAR.

    Hello folks,
    I have recently learned the class loader hierarchy that is employed in
    the WebLogic server. Previously, I was including the local component
    interfaces of my EJBs in the EJB JAR file as well as the web
    application WAR file. However, since the EJB class loader is the
    superclass of the WAR class loaders, the WAR class loader can see all
    classes in its level as well as the level above it (the EJB class
    loader and system class loader). Therefore, I removed the Local
    component interfaces from the WAR file, and the system works fine.
    However, I have various utility/helper classes that are in the EJB JAR
    file as well as the WAR file. Is it safe to remove them from the WAR
    file? Is there any need to duplicate classes in the JAR/WAR file if
    they are packaged together as an EAR file? Any input is highly
    appreciated.
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669

    No, your helper classes will also be visible to the war class loader.
    You might also consider packaging your helper classes in a separate jar
    file. Then add a manifest class-path entry in your ejb.jar and your
    web.war that references the utility jar file(s). This should work on
    any J2EE server.
    -- Rob
    Ryan LeCompte wrote:
    Hello folks,
    I have recently learned the class loader hierarchy that is employed in
    the WebLogic server. Previously, I was including the local component
    interfaces of my EJBs in the EJB JAR file as well as the web
    application WAR file. However, since the EJB class loader is the
    superclass of the WAR class loaders, the WAR class loader can see all
    classes in its level as well as the level above it (the EJB class
    loader and system class loader). Therefore, I removed the Local
    component interfaces from the WAR file, and the system works fine.
    However, I have various utility/helper classes that are in the EJB JAR
    file as well as the WAR file. Is it safe to remove them from the WAR
    file? Is there any need to duplicate classes in the JAR/WAR file if
    they are packaged together as an EAR file? Any input is highly
    appreciated.
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669

  • Reading a fixed length file

    Hi All,
    I am trying to read a fixed length file with .DAT extension through an FTP Adapter. I am using a read(polling) operation.
    In the file there are three records(H,D,T). The length of all the three records is more than 100.When I am trying to build a schema for that file using native format builder, maximum position that i get is 100 and if i manually try to put the position beyond 100 say 120,while building the schema and then run the composite using the generated schema, the file is not polled from the location So if anyone could help me to clarify my doubts regarding reading of fixed length files.
    a. Can i read i fixed length file which contains records whose position is more than 100.
    b. If yes, then how do i do that?
    Any help is appreciated.
    Thanks in Advance.

    Here's one way to start. Extend this class for the particular functionality you want:import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    /** Processes binary files which have embedded data records. */
    public abstract class BinaryInputFile extends File
    * Class constructor.
    * @param fileName The input file name.
    * @throws NullPointerException if the <code>pathname</code> parameter is <code>null</code>
    protected BinaryInputFile(String fileName) throws NullPointerException
       super(fileName);
    * Reads the file, one line at a time, passing each line to the subclass� process()
    * function.
    * @throws IOException if an error occurs.
    public void process() throws IOException
       DataInputStream stream = new DataInputStream(new FileInputStream(this));
       process(stream);
    * Process the file data.
    * @param stream The input stream.
    protected abstract void process(DataInputStream stream);
    }

  • WAR file fails to deploy WEB-INF/classes

    Hi All
    I am attempting to get a simple JPA on JSE app running on WLS 9.1. I can deploy my WAR file and access the jsps no problem, however the WEB-INF/classes directory is empty on deployment. How can I tell if the classes are being deployed correctly? I have tried using autodeploy and console deployment, always with the same result. My war file is structured as follows:
    WEB-INF/
    WEB-INF/faces-config.xml
    WEB-INF/weblogic.xml
    WEB-INF/web.xml
    WEB-INF/classes/
    WEB-INF/classes/my/test/package/{all classes}
    WEB-INF/lib/{all reqd libs}
    index.jsp
    When I run the jsp, there are no errors, the classes just don't appear to be doing anything. The logs have absolutely nothing to help with this, I turned on app logging in weblogic.xml and it has nothing other than the initialization in it either.
    I've deployed and run the exact same app (less the weblogic.xml file) successfully on Tomcat and OC4J, any ideas out there? Am I looking in the right place for the deployed class files (Checking the WL_HOME/samples\domains\wl_server\servers\examplesServer\tmp\_WL_user\jpa-example\xb6q08)?

    Hi,
    I've faced the same issue in WLS9.2, and but it didn't affect my web application running, I guess that the classes are read from the WAR file directly, so for me to overcome this issue, I've changed the technique of how to install web application by selecting extracted war installation instead, and from the WLS Console selected
    "I will make the deployment accessible from the following location" and selected the folder that contains the extracted WAR.
    Hope this will help,
    Issa

  • Class not found error when jar in war file

    I am using Java Creator 2 and have a project. The required libraries have been added to the library manager and the "package" checkbox has been checked. This means they will be added to the deployment.
    After deployment, I check the war file and it contains the proper libraries. However, when I run it by using the "run main project" option from the menu there is ClassNotFound exception. The class that cannot be found is in one of the jars in the war file. As I said, I have checked this war file after deployment and it contains the jar.
    Only thing I can think of is that another classloader is being used. Incidentally, (I hope), the missing class file is related to hibernate. During the creation of the Hibernate session factory, it cannot find this file. But hibernate should have nothing to do with it. The fact is a class file cannot be found even though it is in a jar contained in the war file.
    Any ideas?

    Did you read the tutorial from Creator?
    David
    http://www.pricerunner.com/forum/viewtopic.php?t=1659

  • How to deploy ear file with jar file and war file with different names

    Hi,
    As part of weblogic migration from WL 6.1 sp3 to WL 10, Iam facing some problem.
    Problem:
    I have one ear file(abc.ear) to deploy which contains one jar file(xyz.jar) and one war file(pqr.war).
    In config.xml file of WL 6.1, it was mentioned as :
    <Application Deployed="true" Name="abc" Path="./config/mydomain/applications/abc.ear">
    <EJBComponent Name="xyz" Targets="myserver" URI="xyz.jar"/>
    <WebAppComponent Name="pqr" Targets="myserver" URI="pqr.war"/>
    </Application>.
    The above is working fine.
    But in config.xml file WL10,I cannot mention the same.
    I need to have different application anmes for ear,jar and war.If I deploy as a ear file,the jar and war files are deployed with the same ear file name.
    I tried the following options:
    1) Deploying as a ear file by adding <sub-deployments>
    2) Deploying both war and jar seperately which is not recommended in my application.
    Please provide the content I should place in the config.xml so that everything works fine correctly.
    Any help is appreciated.

    Hi,
    As part of weblogic migration from WL 6.1 sp3 to WL 10, Iam facing some problem.
    Problem:
    I have one ear file(abc.ear) to deploy which contains one jar file(xyz.jar) and one war file(pqr.war).
    In config.xml file of WL 6.1, it was mentioned as :
    <Application Deployed="true" Name="abc" Path="./config/mydomain/applications/abc.ear">
    <EJBComponent Name="xyz" Targets="myserver" URI="xyz.jar"/>
    <WebAppComponent Name="pqr" Targets="myserver" URI="pqr.war"/>
    </Application>.
    The above is working fine.
    But in config.xml file WL10,I cannot mention the same.
    I need to have different application anmes for ear,jar and war.If I deploy as a ear file,the jar and war files are deployed with the same ear file name.
    I tried the following options:
    1) Deploying as a ear file by adding <sub-deployments>
    2) Deploying both war and jar seperately which is not recommended in my application.
    Please provide the content I should place in the config.xml so that everything works fine correctly.
    Any help is appreciated.

  • How To Access a jar file present outside the war file through a jnlp

    Aoa
    I m new to this forum
    I m having problem with my jnlp file
    i want to know is there any way to access a jar file through jnlp.The problem is that my jnlp file is present in the war file
    and i want to know how to acess a jar file through this jnlp.The scenerio is as below
    I m using ear file on jboss.Its hirerchy is as
    -PAN-war.war
    -launch.jnlp
    -PAN-app-client.jar
    my jnlp file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/" href="PAN/launch.jnlp">
    <information>
    <title>PanEmirates</title>
    <vendor>M Fazal Ur Rehman</vendor>
    <description>PanEmirates</description>
    <description kind="short">PanEmirates</description>
    <homepage href=""/>
    </information>
    <security>
    <all-permissions/>
    </security>
    <resources>
    <j2se version="1.5+"/>
    <jar href="PAN-app-client.jar" download="eager"/>
    <jar href="lib/javafxrt.jar" main="true" download="eager" />
    <jar href="lib/Filters.jar" download="eager"/>
    <jar href="lib/javafx-netbeans-fxuserlib.jar" download="eager"/>
    <jar href="lib/swing-layout-1.0.3.jar" download="eager"/>
    </resources>
    <application-desc main-class="net.java.javafx.FXShell">
    <argument>pan.Main</argument>
    </application-desc>
    </jnlp>
    when i run launch.jnlp file it says unable to download resource http://localhost:8080/PAN/PAN-app-client.jar
    how to access this jar file
    Any help or comment would be highly appreciated
    Regards
    M Fazal Ur Rehman

    Excellent question. I don't see any client-jar in your EAR file structure. So I am assuming you are writing a separate client application which will talk to the ejbs deployed as part of this EAR. You need to do the following:
    Write another EAR file with the following structure:
    ear:
    META-INF/application.xml
    util.jar
    client.jar
    client.jar should have a META-INF/MANIFEST.MF and that should contain Class-Path:util.jar and value for Main-Class attribute.
    Now deploy this new ear to your application server and execute it using Application Client Container that comes with your app server.
    If you don't want to write another EAR file, then bundle th client.jar in your original EAR file.
    Points to note are:
    you have to repackage util.jar again inside this ear file.
    For portability reason, you should use Class-Path manifest entry in client.jar. Refer to http://java.sun.com/j2ee/verified/packaging.html and J2EE platform spec section #8.2.
    Hope this helps,
    Sahoo

  • Wl6.1, war files and 2 letter jar files....

    Hi,I have finally found why my WAR file isn't loading with weblogic 6.1. It seems that it doesn't like two letter class libraries (eg ab.jar) and will through a vague error message at deployment (Prefix string too short). I don't know what has changed between 6.0.2 and 6.1 in this area, but its worth making it apparent to developers in general.Regards,Mark BarryHewlett-Packard Consulting

    Are you saying that this error doesn't occur in 6.0?
    I think i knew what's the problem is, but it would be helpful if you could post the stack trace?
    Mark Barry wrote:
    Hi,I have finally found why my WAR file isn't loading with weblogic 6.1. It seems that it doesn't like two letter class libraries (eg ab.jar) and will through a vague error message at deployment (Prefix string too short). I don't know what has changed between 6.0.2 and 6.1 in this area, but its worth making it apparent to developers in general.Regards,Mark BarryHewlett-Packard Consulting

  • OAS 10.1.3 isn't detecting /WEB-INF/lib jar files within WAR file

    Hello,
    I have been developing and testing a simple non-EJB web application on Tomcat 5.5 with no class loading difficulties for the past several months. All of the needed JARs for my app are located under the WEB-INF/lib directory. My next task is to deploy the WAR file containing my webapp on the Oracle 10g (10.1.3) application server.
    The problem I am having when trying to do this is that when I deploy the WAR file from Oracle Enterprise Manager, the WAR file will expand correctly but at runtime OAS doesn't appear to be detecting the JAR files in the WEB-INF/lib folder of my WAR file. I have confirmed that the JAR files are indeed being expanded in the directory that OC4J expands the WAR file into:
    appserver/j2ee/home/applications/appEARFile/MyWebApp/WEB-INF/lib.
    But when I run the application, from the Firefox browser I immediately get the following 500 Internal Server Error:
    "Servlet error: Error instantiating servlet 'reports'. Servlet class org.springframework.web.servlet.DispatcherServlet not found in web-application MyWebApp"
    (The IE browser just gives me the 500 error without additional elaboration.)
    But my spring.jar where that class is located is in the WEB-INF/lib directory. Does anyone have an idea what the solution is--how can I get OC4J to read the spring.jar (or any jar) in that lib folder? (Or is there a way I can configure logging to better pinpoint the problem if that isn't it?)
    Thanks,
    Glen

    Glen,
    You said:
    IE browser just gives me the 500 error without
    additional elaborationTry unsetting the "Show friendly HTTP error
    messages".
    From the "Tools" menu of Microsoft Internet Explorer,
    choose "Internet Options".
    (You should then see another window entitled
    "Internet Properties" displayed.)
    Select the "Advanced" tab and search for "Show
    friendly HTTP error messages".
    Excellent--that worked. Thanks! I was afraid that I would have to be debugging on Firefox exclusively.
    I also suggest setting the
    "search-local-classes-first" attribute, of the
    "web-app-class-loader" element, in your
    "orion-web.xml" file to 'true' (if it isn't
    already).
    That did it. My orion-web.xml file was of the old DTD-based version, I believe that was causing the problem.
    The following document:
    Oracle® Containers for J2EE
    Developer’s Guide
    10g Release 3 (10.1.3)
    Part No. B14433-01
    has a chapter (3) entitled Utilizing the OC4J
    Class Loading Framework which contains a section
    entitled Troubleshooting Class Loading-Related
    Problems in OC4J.
    Thanks for the link, I went through it thoroughly in trying to fix my problem.
    Glen

  • Versioning JAR/WAR/EAR and CLASS files

    Does anyone know of a standard, defined and recommended way of versioning JAR/WAR/EAR files?
    I guess I can put version information in the Manifest.mf file, but is there a recommended way?
    Another related question is how do I go about versioning individual class files?

    There's not only a recommended way, but a standard way. See http://java.sun.com/products/jdk/1.2/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning).
    However, I've found that this practice is unfortunately not as widespread as one would like. sigh
    What do you mean by "versioning" individual class files (in a JAR, I assume you mean)? In general that's a bad idea. But perhaps I misunderstand what you mean.

Maybe you are looking for