Accessing resource files inside Jar using Fat Jar Eclipse plugin

Hi,
I want to develop single JAR file that uses a set of other JAR libraries. I am using Fat Jar Eclipse plugin. It works fine. However, I have problem to access resources files (i.e. rdf file) using relative path from my classes. Is there any idea how can I pack, set classpath and use relative path in order to make it works.
Thanks
Zoran

I have solved this problem. The problem was in a way how I have trying to access it. It should be like:
URL fileURL = this.getClass().getResource("resource/myFile.rdf");
Zoran

Similar Messages

  • Accessing Resource file in a bundle from unit test case

    Hello All,
    Here is my problem . I have a plugin app that is loaded in of the host application. I have a resource plist file in the plugin. I access the resource using the api [[[NSBundle mainBundle[ bundleWithIdentifier:@"MyPluginIdentifier"] pathForResource@"Resource_Name" ofType:@"Resource_Type"]. This I get path of the resource file perfectily, but it fails when I do unit testing. I am using SenTest framework kit for unit testing. When I access the resource by using above api, I get null value. Since the running executable will be otest which is located at /Developer/Tools folder, So how to access my resource file in unit test. Should I need to hard code for the Path? Any inputs are highly appreciated.
    Thanks,
    Naveen

    So there is some important stuff realized by the UIKit UIApplicationMain function that has to be reproduced in the setup of the test.

  • JAR using another JAR

    Hi,
    I have created in Eclipse simple class Blah.class:
    public class Blah {
         public Blah() {
              System.out.println("Inside blah");
    Then I made a JAR file: C:\Blah.jar
    Then I made in Eclipse another project with a simple class BlahBlah.class and linked Blah.jar file in this project:
    public class BlahBlah {
         public BlahBlah() {
              System.out.println("Inside BlahBlah");
              Blah b = new Blah();
         public static void main(String arg[]) {
              BlahBlah bl = new BlahBlah();
    Then I made another JAR file C:\MyJar\BlahBlah.jar from this project as an executable JAR.
    But when I tried to run the second JAR from command line bad things happened. This is the output:
    C:\MyJar>java -jar BlahBlah.jar
    Inside BlahBlah
    Exception in thread "main" java.lang.NoClassDefFoundError: Blah
    at BlahBlah.<init>(BlahBlah.java:5)
    at BlahBlah.main(BlahBlah.java:8)
    Java execution started, but first JAR (C:\Blah.jar) was not found. In CLASSPATH variable I have following value: C:\Blah.jar
    So, what am I doing wrong?
    Thanks in advance. Lokutus.

    When executing a jar, that jar has a personal classpath if I'm not mistaken, the CLASSPATH variable is ignored (which is logical, because only your system has that classpath. When executing the jar on another system you want the jar to execute without any environment variables being needed).
    I know that in the META-INF/MANIFEST.MF file inside the executable jar you can list jar files that the executable jar depends on. The line would look like:
    Class-Path: jar1.jar jar2.jar
    and so forth (seperate by a space). What I don't know is how to make the mkjar tool create this line... google is probably your best friend.

  • Problem loading resources file in JSP using f:loadBundle

    Hi,
    We are facing problem while loading our properties file in JSP using f:loadBundle.we tried the following way
    <f:loadBundle basename="resources.ApplicationResource" var="msg"/>
    This properties file is src java folder and also in WEB-INF-->classes->resources folder
    but even then its not able to load.I made an entry in the faces-config for message-bundle. But of no use.
    Any pointers would be of great help.

    does your file calls
    ApplicationResource.properties ?
    If so is it in
    the package resources ?

  • Getting the path of  a resource file inside the context

    I am trying to migrate some of our applications running on OracleApplicaiton Server. We have data resource xml file needs to use in the applicaiton. In Oracle Application server we used to give the actual path of the xml file to load the xml file to the parsers since we know the path of the directories after deploying the application as an ear file. How can I get the path of the files in weblogic after deployment. If this is not supported what is the alternative to get the relative path of that xml file to load in ? The xml file is in the root folder of the context.
    THanks
    Suneesh

    Hi Suneesh,
    Please try enabling the <show-archived-real-path-enabled> Tag to TRUE ...And then everything will work fine with the following code:
    context.getRealPath()
    At domain level in config.xml. For example:
    <web-app-container>
    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
    </web-app-container>
    *****OR *****
    At the web app level in weblogic.xml. For example:
    <container-descriptor>
    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
    </container-descriptor>
    For Archived Applications , It is always a best practice to use the getResourceAsStream() rather than using getResource().......Below code snippet should workout in 99% cases
    InputStream stream=this.getClass().getClassLoader().getResourceAsStream("someXMLorPropfile.properties");
    Thanks
    Jay SenSharma
    http://middlewaremagic.com/weblogic/?p=408  (Middleware Magic is Here)

  • Developing SOAP based Webservice using Axis 2 Eclipse plugin

    Hi,
    I want to develop a SOAP based Webservice which connects to the PostgreSQL DB , by fetching the data for the employeeId entered and display the results in the browser. I'm using using JDK 1.6, Tomcat 6.0, Axis 2.0 , with Axis 2 Eclipse Plugin. Please send me a sample code of how to build it, i am able find some examples on the internet, but none of them are related to connecting to the DB and fetching the data. It will be great if you guys can provide the sample application which does have the same functionality as mine. Please do respond as this is urgent. Thanks in advance..
    Thanks,
    Rithu

    Thanks Adhir Mehtaji, This is what i have come up with, developing a webservices based on SAAJ and deploying that in Tomcat server, here is the Webservice and the other related files:-
    public class EmployeeService {
         * This method returns the Employee Name
         * @param empId String
         public void getEmployeeName(SOAPEnvelope req, SOAPEnvelope resp) throws javax.xml.soap.SOAPException {
              System.out.println("Inside the getEmployeeName in Employee Service");
              IEmployeeDAO employeeDAO= null;
              employeeDAO = new EmployeeDAOImpl();
              SOAPBody body = resp.getBody();
              String empId = null;
              NodeList empIdNodeList = req.getBody().getElementsByTagName("empId");
              for( int i=0; i < empIdNodeList.getLength(); i++ ) {
                   Element empIdElementElement = (Element) empIdNodeList.item(i);
                   Node empIdNode = empIdElementElement.getChildNodes().item(0);
                   empId = empIdNode.getNodeValue();
                   System.out.println("the empId in the employee service is:::"+empId);
              addNode(body,"empName",employeeDAO.getEmployeeName(empId));
              //addNode(body,"segmentName1",custSegmentDAO.getSegmentName(ZipCode));
         private static void addNode(SOAPBody body,String nodeName,String nodeValue) throws SOAPException{
              body.addChildElement(nodeName).addTextNode(nodeValue);
         This Service is exposed as a Webservice which connects to the DAO and get the response for the EmpId.
         This is the client file:-
         public class GetEmployeeNameClient {
              public static void main(String[] args) throws Exception {
                   // Invoking the Webservice endpoint which is hosted (deployed) in Tomcat by passing the SOAP Message request
                   // Get the SOAP Message response , which contains the employee name for the empId 100
                   // Parse the SOAP Message response to get the employee name (response from the WS)
                   String[] nodeNames = { "empId" };
                   String[] nodeValues = { "100" };
                   SOAPMessage message = GetEmployeeNameClient.getMessageFactory(
                             "getEmployeeName", nodeNames, nodeValues);
                   SOAPConnection conn = SOAPConnectionFactory.newInstance()
                             .createConnection();
                   SOAPMessage response = conn.call(message,
                             "http://localhost:8080/axis/services/EmployeeService");
                   // If the response is not null then everything is fine with the WS.
                   System.out.println("the response is what???"+response);
                   System.out.println("\n Soap response:\n");
                   System.out.println("\nXML response\n");
                   // Create transformer
                   TransformerFactory tff = TransformerFactory.newInstance();
                   Transformer tf = tff.newTransformer();
                   // Get reply content
                   Source sc = response.getSOAPPart().getContent();
                   // Set output transformation
                   StreamResult result = new StreamResult(System.out);
                   tf.transform(sc, result);
                   System.out.println();
                   // For these to work we need to connect to the DB - jdbc:oracle:thin:@ora-b2cd:6473:b2cd to get the segment name
                   SOAPBody soapBody = response.getSOAPBody();
                   System.out.println("the soapBody is what???"+soapBody);
                   NodeList empNameNodeList = soapBody.getElementsByTagName("empName");
                   System.out.println("the empNameNodeList.getLength is::"+empNameNodeList.getLength());
                   for (int i = 0; i < empNameNodeList.getLength(); i++) {
                        System.out.println("inside the loop");
                        Element empNameElement = (Element) empNameNodeList.item(i);
                        System.out.println("the empNameElement is what???"+empNameElement);
                        Node empNameNode = empNameElement.getChildNodes().item(0);
                        System.out.println("the empNameNode is what???"+empNameNode);
                        System.out.println("Employee Name For empId is ...... "
                                  + empNameNode.getNodeValue());
              // Construct the SOAP Message request by passing the empId 100(should come from UI)
              private static SOAPMessage getMessageFactory(String methodName,
                        String[] nodeNames, String[] nodeValues) throws SOAPException {
                   SOAPMessage message = null;
                   try {
                        System.out.println("Inside the getMessageFactory");
                        MessageFactory messageFactory = MessageFactory.newInstance();
                        message = messageFactory.createMessage();
                        SOAPPart soapPart = message.getSOAPPart();
                        SOAPEnvelope envelope = soapPart.getEnvelope();
                        SOAPBody body = envelope.getBody();
                        SOAPElement bodyElement = body.addChildElement(envelope
                                  .createName(methodName));
                        for (int index = 0; index < nodeNames.length; index++) {
                             bodyElement.addChildElement(nodeNames[index]).addTextNode(
                                       nodeValues[index]);
                        message.saveChanges();
                        // View input
                        System.out.println("\n Soap request:\n");
                        message.writeTo(System.out);
                        System.out.println();
                   } catch (Exception e) {
                        e.printStackTrace();
                   return message;
         This client will send a SOAPMessage with EmpId (100) as a request and get the response from the Webservice as SOAPMessage , which
         contains the empname for the respective empid which is passed.
    I tested this service in the browser, it is up and running through the URL : http://localhost:8080/axis/services
    But when i try to access the webservice to get the response from my client program, i am getting the following SOAP Fault string:-
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body><soapenv:Fault>
    <faultcode>
    soapenv:Server.userException
    </faultcode>
    <faultstring>
    org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/properties/lexical-handler
    </faultstring>
    <detail>
    <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">
    user-15bbc0db6e
    </ns1:hostname>
    </detail>
    </soapenv:Fault>
    </soapenv:Body>
    </soapenv:Envelope>
    My client path contains :-
    axis.jar;
    jaxrpc.jar;
    saaj.jar;
    commons-logging.jar;
    commons-discovery.jar;
    wsdlj4.jar;
    axis-ant.jar;
    log4j-1.2.4.jar
    xerces.jar
    activation.jar
    mail.jar
    Similary the in the d:/tomcat/webapps/axis/WEB-INF/lib,contains the same as that in client path.
    I am using Tomcat 6.0 , JDK 1.6, I have googled and found that the expection is due to "Xerces.jar" not in Tomcat/webapps/axis/WEB-INF/lib.
    I have copied xerces.jar in the said path, still the error persists. Please do provide a solution to this. Where i have gone wrong.
    I have one more query, If i have to rest a "list" as a response from the server (webservice), how i can add the list into the SOAPMessage? Whether i need to parse it and add the values one by one in the SOAPMessage? like
    <empname> xxxx</empname> <empage>25</empage>
    <empname> yyyy</empname> <empage>26</empage>
    Please answer these queries.
    Thanks,
    Rithu

  • Access Denied Socket Permission Error using 3rdParty jar in webstart

    Hi,
    I am trying to create a multisocket in my application, and this app is downloaded through webstart,
    Following are the things I ve done,
    1. I use two jnlp file, one mail jnlp file (say a.jnlp) and the other an extension jnlp file (a_ext.jnlp) which contains the third party jars.
    2. I used <security><allpermission/><security/> in both the jnlp files.
    3. If I try to create a multisocket in my code that is downloaded through main jnlp i.e. a.jnlp file, then it is working fine.
    4. But the problem is, the third party jar which is downloaded throught "a_ext.jnlp" file is trying to create a multisocket
    and i am getting the following error,
    +java.security.AccessControlException: access denied (java.net.SocketPermission 228.0.0.4 connect,accept,resolve)+
    + at java.security.AccessControlContext.checkPermission(Unknown Source)+
    + at java.security.AccessController.checkPermission(Unknown Source)+
    + at java.lang.SecurityManager.checkPermission(Unknown Source)+
    + at java.lang.SecurityManager.checkMulticast(Unknown Source)+
    + at java.net.MulticastSocket.joinGroup(Unknown Source)+
    + at inria.net.MulticastSession.initialize(MulticastSession.java:143)+
    + at inria.net.lrmp.LrmpImpl.<init>(LrmpImpl.java:105)+
    + at inria.net.lrmp.LrmpImpl.<init>(LrmpImpl.java:89)+
    + at inria.net.lrmp.Lrmp.<init>(Lrmp.java:194)+Please help me.
    Note that I dont want to create any policy file, I want some configurations to be done in jnlp files or in the jars, because i cannot create a policy file and copy it manually in each client deployment.

    >
    And sorry that jnlp is a valid jnlp only, ..>
    How do you know? Did you validate it, or are you just guessing?
    >
    ..and it was a typing mistake, ..>So don't retype these things, instead copy/paste them.
    >
    it is </security> not <security/>>it is also <all-permissions/>, not <allpermission/>
    >
    and when i start through webstart it is asking for confirmation also, so i think this <security> tag is working fine.>Stop thinking and start validating.
    >
    But the problem is with security for the 3rdParty jar downloaded through jnlp extension. >So it will be most important to validate that. Note that if this 3rd party extension is signed by the people that supplied it, you should get a second security prompt.
    >
    ... I hope JNLP doesnt check or give permission for the jars downloaded via extension jnlp?>What does that mean?
    OTOH, I just noticed you assigned the princely sum of 1 entire duke star for this question. It is obviously of only minor importance to you, so my time is better spent elsewhere.
    Good luck with it.

  • Accessing Informatica File Archive Service using its native JDBC driver

    Good morning,
    Using the Informatica ILM suite, we've retired a number of database applications (which ran on Oracle) into the so-called Optimized File Archive, or OFA.
    The information stored in there can be accessed using their File Archive Service, or FAS.
    To allow access for certain tools, they've also got an ODBC and JDBC driver (from the original company that created the archive bit, RainStor), to be able to get to tables in archives.
    I've been able to set it up for Aquafold's Aqua Data Studio (ADS), but given that that is shareware I've only got an evaluation version, expiring in 2 weeks.
    Since SQLdeveloper, like ADS, is a Java-based tool, and it also allows for third party JDBC drivers, I'm inclined to think that somehow SQLdeveloper should also be able to connect to those archives. Unfortunately, I always get an error message: "Invalid connection information specified. Verify the URL format for the specified driver"
    There are some slight differences between ADS and SQLdev in setting up such a JDBC connection.
    In ADS, apart from providing user/pw, I have to specify following:
    - name of the JDBC driver ("com.simba.client.core.SimbaJDBCDriver")
    - location of the JDBC driver (e.g. "C:\Ora\RainStorJDBC-3.0.1.2.jar")
    - JDBC URL of format "jdbc:simba://<host>:<port>;Archive=<archive>;ConnectionTimeout=3600;Parser=ORACLE"
    In SQLdev I can import the JDBC driver (menu > Tools > Preferences, then under Database > Third Party JDBC Drivers), and in the Database Connection Screen create a new connection, provide the user/pw of the so-called Service Manager (from FAS), and choose Connection Type "Advanced" to then specify the "Custom JDBC URL", which would have to be the same as above. If I test the connection, I get an instant error:
    "Status: Failure -Test failed: Invalid connection information specified. Verify the URL format for the specified driver".
    Informatica's Global Customer Support are saying that SQLdev can't do it, but I'm just wondering whether some really bright lights in the Oracle community have found an alternative route to be able to connect to such FAS/OFA archives. Given the similarities between ADS and SQLdev, to me it seems it - somehow - has to be possible as well...
    Thanks in advance for thinking about this problem/challenge.
    Cheers!
    Edited by: exapat on Dec 7, 2012 10:43 AM
    Did some further investigations, on other third party drivers. Those ones (e.g. for SQL Server) - when loaded - create an extra tab in the connection screen.
    The RainStor JDBC driver does not do that, and I can imagine that that's where it falls short.
    If indeed the case, what could be done to overcome this?

    Hi,
    Did some further investigations, on other third party drivers ... If indeed the case, what could be done to overcome this?That is the case. Currently browsing and migration support for third-party databases is limited to the following:
    http://www.oracle.com/technetwork/developer-tools/sql-developer/supportedmigplatforms-086703.html
    See section 1.1 for currently supported databases and section 1.3 for those planned for a future release.
    To see an example of some (all?) of the extra bits needed to support browsing of a third-party database, find the extensions directory in your SQL Developer installation, look for
    oracle.sqldeveloper.thirdparty.browsers.jarthen browse it to see the various class, properties, and xml files necessary for supporting connections to databases like mysql or sybase. You may conclude adding browsing support is not all that complicated. Migration support is an entirely different matter, however. Oracle is the thirdparty.browsers extension owner. Support for more third-party databases would normally be added by the SQL Developer group based on a database's general popularity or a feature request on the SQL Developer Exchange -- obviously a long-term proposition.
    If you look at the [Extensions Exchange|http://www.oracle.com/technetwork/developer-tools/sql-developer/extensions-083825.html] maybe you can get some ideas how best to proceed if you have the resources to build your own extension to support RainStor.
    Regards,
    Gary
    SQL Developer Team

  • How to access XML files inside IDML?

    Hi All,
    How to access the different XML files like designmap, story, masterspread, etc. found inside the IDML files?
    Pl. help.
    Thanks,
    Praveen

    An External Library DC is only intended to include jars. Using a Java DC may be a better idea, unless you put your xml files into a jar first (but you'd need a Java DC for that...).

  • Building jars using ant and eclipse

    Note: If this post could be in a more appropriate forum category could someone please tell me which one is better.
    Vexing issue:
    I am using ANT so that it will take care of which classes have been modified and therefore which jars need to be updated.
    I noticed one way ANT can work is to look at the timestamp of the class files and then build the necessary jars. This works fine EXCEPT that eclipse has a nasty habit of sometimes recompiling everything, even when I dont ask it to. It would seem to make more sense basing the recompilation on the source files, and whether they have been modified. So I set this up with my build.xml, ie
    <target name="compile" depends="init"
    description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}" fork="true"/>
         </target>
    Now suppose I go and change one of my source files, ANT recompiles that file and that all works great. However, suppose that file had in it, which many do,
    public static String EXAMPLE_VARIABLE = "example";
    This static variable is referenced in many classes, and yet ANT only recompiles the one file, and thus there begins an inconsistency!
    Is there any way to get around this? I would have expected ANT to recompile all the files that depend on the class with the static variable but it doesnt.
    Any help much appreciated.
    Cel

    You know, that's a good question. I would think JVMs at runtime could resolve static variables, like when it compiles classes using that static variable it puts a placeholder "Hey, here I am using XXX, at runtime, figure it out and give me the value right at the start..". But I think it works like you suggest in that a static value is compiled into every location that uses it. The only thing I can think of is provide a target for a build-all in your ant and have it rebuild all.
    I agree though that the javac compiler should be smarter in how it compiles classes. Anytime a class has certain attributes that may be compiled in to other classes, it should check and recompile any class that depends on the static value that has changed.

  • Access resource from other application using JAAS

    i use JAAS for autenticate and autorizate in my web application, but i need access a resource from the other application , but this application don�t use JAAS.
    How can i acces this resource from other application?
    i know need send the parameters JSESSIONID, but , always redirecto the login page.
    thank you for your help

    your signon url is consists of the following url http://server.domain.com:port/site/signon.html
    Can you ping server.domain.com from your client?
    If you can ping it, then make sure your port is added as a rule in the firewall of the server.
    Also make sure that the proxy setting of the client have an exception to server.domain.com.
    If you cannot ping it, make sure the server and the client are conneted to the same network and make sure the hosts file on the client reflects the ipaddress and the hostname of the server.
    Hakan

  • Access pdf files on-line using iPlanet as server

    We are using Sun One Web Server as server. Our system generate files in pdf fomat and this pdf format must be available online. We created a folder inside server machine directory e.g. /var/opt/generatedreports/ .. The pdf files will open once a user clicks on the link.
    how could i check this directory-mapping?

    Ok, thanks. I think I will find a way to show the files. Maybe i'll use a jsp page instead. Thanks again.

  • Access data file inside a package

    Hi,
    I have data files (text type) inside a folder of the same package where the classes are. How can I access those data file?
    String infile = getClass().getPackage().getName()+"/data/T1901c.txt"; // shows error as getClass().. returns URL
    InputStream in = new FileInputStream(infile);

    Hi,
    I need FileInputStream whereas getResourceAsStream(String name) is InputStream type.
    How to solve it?

  • Can not find files inside folder using enterprise keywords.

    I'm using a document library web part. The using Enterprise Keywords. I have a "Health Insurance" keywords that I added to 8 documents. These document are inside a folder call Benefits. I went to web part editor and clicked on "Edit the current
    view" Then I changed the filter to "Enterprise Keywords is equal to Health Insurance" Lastly I went to the Folders section and selected "Show items inside folders".
    After I click "OK", I'm presented with an empty documents web part.
    What can I do to get the files to show up?
    Thanks
    James T.F

    Hi James,
    Thanks for posting your issue, I am sure that issue is your filter that you have created with "Enterprise
    Keywords" because as per my understand you are able to see the documents with your
    current view of the webpart.
    Please check the filter settings and criteria properly. You should be able to see the expected results
    in Web part.
    I hope this is helpful to you. If this works, Please mark it as Answered. 
    Regards, 
    Dharmendra Singh (MCPD-EA | MCTS) 
    Blog :
    http://sharepoint-community.net/profile/DharmendraSingh

  • How can i  create and access resource file(with .res ext) in j2me

    hi,
    i am developing an mobile international application using jsr-238 an optional api to implement the idea of internationalizationand localization.
    please tell me how can i create .res files in my application to store strings of different languages.thanks inadvance.

    Hello GG RA,
    which fileformat do you want to use (binary or ASCII)?
    There are some LabVIEW shipping examples for File I/O
    You could use the LabVIEW NI Example Finder (Help --> Find Examples..(search item "file")) to get an overview about the different file-formats in LabVIEW.
    Hope this helped out and feel free to reply if you have more questions about File I/O in LabVIEW
    Best regards
    Benjamin

Maybe you are looking for