Set the path to the jar file

Sorry for the noob question, but could you tell me please what I did wrong when I try to set the path to the file in my application jar.

I have app that works with the xml file. I have the following project structure:

/project_root_directory

| / lib _

| /resources/file.XML _

| / SRC _

So, I need set my jar file, because when I correctly by running the IDE, it works well.

By default, it seems:

private File file;
private StreamResult streamResult;
file = new File("resources/file.xml");
streamResult = new StreamResult(file);



And methods where I can change the DOM structure via transformer end methods:

transformer.transform(source, streamResult);



So, I tried sets the path to the file:

private URL url;
...

file = new File(url.getPath());
streamResult = new StreamResult(file);



But it does not, because when I try to get resources by the following condition

url = getClass().getResource("resources/file.xml");



(" url = getClass().getResource("resources/file.xml "); URL = getClass () .getResource ("url = getClass().getResource("resources/file.xml "); (" resources/file.xml ');

URL - is null

OK...

I tried the following solution

InputStream input = getClass().getResourceAsStream("resources/file.xml");

Here, I myself also null...

This solution I found here

Also, I tried in absolute path

filePath = file.getAbsolutePath();
file = new File(filePath);
streamResult = new StreamResult(file);



But he also didn't work. There I got message seems to be: "Cannot find the /User/user1/Desktop/program1/resources/file.xml resource" - but it really is absoulte path to a file.

Also, I tried using System.getProperty

String filename = "file.xml";
String workingDir = System.getProperty("user.dir");
finalfile = workingDir + File.separator + "resources" + File.separator + filename;
file = new File(finalfile);


I also did test unit that finished with the 'green light', but potted his wrong with the message "unable to find /User/user1/Desktop/program1/resources/file.xm resource.

Could you tell me please what I did wrong?

file:\c:\Users\user1\Desktop\myapp.jar!\psswd.XML is what getResource() book you as the URL of the entry of the pot (notice I didn't say file, but the entrance of pot).

The meaning is: the psswd.xml of the entrance lies at the root of the C:\Users\user1\Desktop\myapp.jar pot.

Now, without taking into account my tips, you want to turn this into a file. If Java puts in front of it in the current directory. If you use Windows Explorer, you have such a file?

psswd.XML is not just a file. In any case, given that your StreamResult is supposed to write something, it may not be in the jar. You can not write to an entry in the pot. Jars is supposed to be read-only.

It's like an EXE file in writing within himself. So psswd.xml should be outside the pot, a real file and forget the things of the resource. It happened to work in the IDE, because there he was jarred not yet.

It happened to be a Windows file and a Java resource.

Tags: Java

Similar Questions

  • I changed my default program to open the .jar files in Java...

    I changed my default program to open the .jar files in Java... but now they all open as windows of command for half a second before disappearing (Windows 8 BTW) so how can I reset it to open it but it feels like it?

    Try the system restore to undo your mistake.

    How to repair the operating system and how to restore the configuration of the operating system to an earlier point in time in Windows Vista (7 or 8).
    http://support.Microsoft.com/kb/936212/#appliesTo

    See, control Panel\All Control Panel Items\Recovery\ Open System Restore

    Take a look at the control Panel\All Control Panel Items\Default Programs\Set Associations and set the correct program for a .jar file.

    Java uninstallation and reinstallation of Java could fix.

    Windows 7 - how [closed] open JAR files

    http://StackOverflow.com/questions/11617239/Windows-7-How-to-open-jar-files

    http://www.Google.com.au/search?q=what+program+or+process+opens+.jar&SourceID=IE7&RLS=com.Microsoft:-to THE: IE-address & ie = & oe = & gws_rd = cr & ei = iyFPUtjtOsvtiAel6oHICQ

  • Cannot open the .jar files more

    Hey everybody.

    Recently, I can open is more .jar files more

    I am running OSX El Capitan 10.11.4

    I am trying to install a mod for a game that is in a .jar file and have recently been unable to do so due to this message:

    ' The Jar Java file could not be started: check the console for possible error messages

    I have installed the version of Java recommended directly on the terminal says it is my Java information and site:

    Java version "1.6.0_65".

    Java (TM) SE Runtime Environment (build 1.6.0_65 - b14-468 - 11 M 4833)

    Java 64-Bit Server VM (build 20, 65-b04-468, mixed mode)

    After some research, I was told to install java on apple here's site - https://support.apple.com/kb/DL1572?locale=en_US , but that didn't work either. I have never had any problems with installing .jar before and this specific mod, I have installed in the past. Is it because of the latest version of Mac OS x? Any help is greatly appreciated, thanks :)

    What's the .jar file executable? You may need to use the command line, i.e., chmod, to make sure. For example

    chmod +x foo.jar

    C.

  • See the contents of the .jar file

    Dear all,

    Good evening from the India.

    Here's the problem I want to share with you all.

    I'm working on Windows 7 Home Basic Version. I downloaded e - tds_tcs_rpu_1.2.ex

    According to the advice of the NSDL-TIN people, I downloaded new e - tds_tcs_rpu_1.3.ex

    Then they advised me to install java update 1.6 29 in your system and your system must be 32-bit, more if you use the Windows 7 operating system or higher then kindly troubleshooting Control Panel. I followed what they advised.

    But I'm still droping in the dark.

    Someone help me please. I'll be very grateful to my friends.

    Java 1.6 is the minimum version, you must install the latest version available.

    I recommend you to uninstall the update above and download the latest being:

    http://www.Oracle.com/technetwork/Java/javase/downloads/jre7-downloads-1880261.html

    not sure that it's valid for you or not, I filled the back using their software online, not by the JAR file.

  • access request to the jar file module

    Hello world

    I use jdev 11.1.1.7.0

    I added a jar file to my project (jar file contains a workflow and an application module), the jspx parent page like the following (also application instance module added to the data control):

    <af:panelGroupLayout id="pgl1" layout="vertical"> 
        ...
      <af:region value="#{bindings.taskflow.regionModel}" id="r1" />     
      ...
    </af:panelGroupLayout> 
    
    

    If I create a bean for the parent jspx page (the page contains the workflow) is it possible to access the instance of request of the jar file?

    Habib

    Concerning

    Post edited by: Habib.Eslami

    Habib, read the warning about the changes to understand the warning of uncommitted data. Then http://andrejusb.blogspot.de/2010/03/integration-in-oracle-adf-with-adf-task.html that shows how to get to the datacontrol to a region and check the status of the transaction.

    Timo

  • Regenerate the JAR files

    Hello

    I'm trying to regenerate the JAR files in ADADMIN but my apps password does not to the
    "Enter the password of the ORACLE Application Object Library [APPS]"

    If I connect to SQL with the same APPS password and his works fine.

    Is there another way I can regenerate the JAR without ADADMIN files?

    Help, please...
    Thank you

    Iqbal wrote:
    I saw the doc above.

    The APPLSYS account has been locked.

    So, can you now connect without any problem?

    Thank you
    Hussein

  • How to add multiple images to a JLabel since the jar file

    I want to add more than one image in a JLabel, but the icon property only allows me to add a. I thought I could use the rendered html to add the images I need using the < img > tab, but I need to use a URL that points to the image.

    How do I point to an image in the jar file? If I can't do it, is there another way to display multiple images in a JLabel since the jar file?

    Discover camickr [http://tips4java.wordpress.com/2009/03/29/compound-icon/ url] composed icon.

    DB

  • can not locate the jar file that contains com.bea.cache.jcache.cacheLoader

    Hello

    I'm trying to create a CEP Application in which an adapter look in the Cache. I knew that in this case, the adapter must implement the interface "com.bea.cache.jcache.cacheLoader" Interface. I see that this interface and the package (com.bea.cache.jcache) is not available in the file wlfullclient.jar.

    Can tell me where can I find the Jar file that contains the perl package, I mean any place where I can download or a steps I follow to get this jar file.

    Thanks in advance for your time,
    Regnier

    Published by: Raja Kumar April 1, 2010 08:19

    Hi reda,.

    It should be in modules/com.bea.core.cache_1.5.0.0.jar or a file with same name

    Andy

  • Legend of java ServiceBus - how to pack the JAR file with the libraries?

    Hello

    I want to use a legend of Java from a stream of Bus Service.

    What is the right way to pack the JAR file with its necessary libraries?

    I have tried different methods to pack my POT, but again, as if Java works perfectly workshop (Eclipse), when I try to use the Jar exported on the ServiceBus stream, it fails with a ClassNotFoundException exception.

    I would appreciate your advice here.

    Thank you

    Koby

    Follow the steps: -.

    1. create a java file with a static method that is running your features
    2. in the container, the file use the following command:-

    jar cvf entry file jar-file (s)

    For example, jar cvf Test.jar Test.class

    3. in the Console ALSB, open the session in edit or design mode. Create a folder (if you wish).

    4 inside of this folder, create a resource > Jar. Select the jar file you created above, and then name the resource. Record.

    5 activate the changes.

    6. in the proxy, AddAction service > Message Processing > JavaCallout.

    7 select the resource and method. Click on submit. (Only static methods defined in the file will be displayed)

    8. you can test by logging the response since the Java file.

    I hope this helps.

  • How to regenerate the JAR files?

    How to regenerate the jar files in adadmin?
    We have eBS R12 from Unix.
    Best regards

    Hello

    Please refer to the Maintenance of Applications Oracle® utilities (4-6, JAR files generate products Page).

    Applications releases 11i and 12
    http://www.Oracle.com/technology/documentation/applications.html

    Kind regards
    Hussein

  • Setting the maximum file name length under Win XP x 64

    I am trying to find a way to set the maximum size of the name files in Windows XP x 64?

    I think I need to set the value of the MAX_PATH limit in environment variables or the Windows registry?  I am running Windows XP x 64 on an NTFS partition, so my theoretical maximum for a file name is 255 characters. Is it possible to put down?

    Destructive how would making this change not my system?

    Thank you

    MAX_PATH is a system/constant variable used when the Windows operating system is compiled.  There is no way to effectively change without recompile Windows from its source code.  Note that this sets the maximum length of the full path to the file, including directories parent so that the only way that a file can actually be 255 characters long would be if it was located in a root directory.  This is not a hard limit, however, there are some programs that can handle path names has more MAX_PATH (for example "Robocopy").

    HTH,
    JW

  • How to set the primary file in custom filter UCM

    Hi all

    I have a requirement where I need to change the primary file that is downloaded.

    I use validateStandard filter and above the file gets checked... I want to change the primary file for some another file...

    But the problem is that I don't get what function I can set the value for the metadata of the primary file.

    Here is my code:

    public int doFilter (workspace ws, linking DataBinder, ExecutionContext cxt) survey DataException, ServiceException
    {
    Report.trace ("IMG_COMPRESS", "Start doFilter", null);

    String xcontentType = binder.getLocal ("xContentType");
    String primaryFilePath = binder.getLocal("primaryFile:path");
    String primaryFileName = binder.getLocal ("primaryFile");

    If (xcontentType.Equals ("CTID24"))
    {
    Report.trace ("IMG_COMPRESS", "Original file path:" + primaryFilePath, null);
    Report.trace ("IMG_COMPRESS", "file name:" + primaryFileName, null);

    Try
    {
    The output if the primaryFile:path are missing
    If (primaryFilePath == null | primaryFilePath.trim () .length () < 1)
    {
    Report.trace ("IMG_COMPRESS", "Could not find the primary file path", null);
    Back to CONTINUE;
    }

    Change the original image (input image) to the compressed Image (output image file)
    primaryFilePath = "E:\\ImgCompression";
    primaryFileName = "compressed.jpg.txt";

    binder.putLocal ("primaryFile:path", primaryFilePath + "\" + primaryFileName);
    binder.addFile (primaryFilePath + "\" + primaryFileName);

    Report.trace ("IMG_COMPRESS", "new Img path:" + primaryFilePath, null);
    Report.trace ("IMG_COMPRESS", "new Image Name:" + primaryFileName, null);
    }
    catch (System.Exception e)
    {
    Report.trace ("IMG_COMPRESS", "Unable to read file", null);
    }
    }
    executed properly, filter return CONTINUE
    Report.trace ("IMG_COMPRESS", "End doFilter", null);

    Return FilterImplementor.CONTINUE;
    }

    There is no function with addFile in the DataBinder class.

    Help, please

    As I understand it, you create your own compression via a custom filter and you want to replace the original file with this compression.

    That being said, why not do exactly as that - the original file is placed in some ~ temp directory on the server (after download), so go ahead, create compression and put it instead of the original file. One thing to consider is the MIME type - if replacing it, it should be the same; If it is not that you had to adjust first some metadata.

  • How to add the JAR files and configuration files to the CLASSPATH when running?

    QUERY:

    During execution, I need to load JAR files and relevant config (.cfg files) and file .properties files in the CLASSPATH and run a specific one of the JAR java program that is available in the CLASSPATH.


    Please send me details of Java API or an example of java program to implement the use case above.


    Thanks in advance.


    During execution, I need to load JAR files and relevant config (.cfg files) and file .properties files in the CLASSPATH and run a specific one of the JAR java program that is available in the CLASSPATH.

    Please send me details of Java API or an example of java program to implement the use case above.

    You do not add to YOUR classpath once your application is launched.

    You create a NEW process for the application you want to run and provide an appropriate environment for it to run in-including the CLASSPATH or PATH environment variables.

    The Java API for the ProcessBuilder class has a simple example that shows how to create the arguments and to launch an external application.

    ProcessBuilder (Java SE 7 platform)

    There are also MANY other examples of the use of ProcessBuilder; just search the net.

  • What is the .jar file or library for oracle.iam.identity.rolemgmt.api

    Hi Experts,
    I use 11.1.1.6.0 version of Jdev.

    I need to use the oracle.iam.identity.rolemgmt.api.RoleManager API in my application, but I'm not able to find the library or the required jar file.
    Someone help me by adding required libraries please.


    Thank you
    Gopi

    Copy client jar (oimclient.jar) of the computer of the IOM

    find the path below
    client/server /.

  • Problem to open the .jar file

    The question open on mac os x 10.11.5 .jar file. Everything was fine before. Java is updated?

    You can view and download Java for OS x here get Java for your Mac - Apple Support

    or try from site Web of Oracle http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.h tml

Maybe you are looking for