Results 1 to 6 of 6

Thread: Access a file in a jar

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Access a file in a jar

    Hello,
    I made a program (Eclipse, Linux) which execute a command (shell). It works fine as it is not in a JAR:
    Code:
    Shell s = new Shell();
    String res = "";
    try {
      / / Execute the command
      res = s.command(". / plugin / check_disk-c ...").consumeAsString();
    }catch...
    Shell is a package found on a good site. It allows one to run Linux commands.
    But my problem: I put it all into a JAR, including the plugins folder containing the executable that call the command line. But it can not find it, it's normal, it looks at the project level and not in JAR. So for now, I copied the plugins folder to the same level as the JAR, and as this is good. But how to be able to include in the JAR? Any help on this is appreciated. Thanks in advance.

    Thank you in advance!

  2. #2
    Join Date
    Nov 2009
    Posts
    356

    Re: Access a file in a jar

    Hello,
    As you correct a manifest, create the jar. It was able to students, say that you have external jar. So for now, I copied the plugins folder to the same level as the JAR, and as this is good! But how to be able to include in the JAR? You can put a jar in a jar. This is not allowed in the java programming language. I think you can extract the files from the jar then you can use them as you need to run the program.

  3. #3
    Join Date
    Dec 2009
    Posts
    204

    Re: Access a file in a jar

    Hello,
    Even i need to know a solution for this kind of a problem, i was also trying this but I did not had a solution for this, so if you guys have a good solution for this then please let me know. About jar in a jar, It is a folder, files which, a folder "plugins" in my main jar. So a single JAR file, but contains a Java class that accesses internal files to JAR. I hope what he is trying to ask is clearer to you guys, because even I have a similar problem with my application.

  4. #4
    Join Date
    Nov 2009
    Posts
    343

    Re: Access a file in a jar

    Hello,
    To run a java archive, use the following command "java [options]-jar archive_java.jar". For versions 1.1 and earlier of the virtual machine, use the command "jre archive_java archive_java.jar classe_principale". For version 1.2 and higher virtual machine, if the java archive includes a manifest specifying the main class to run, no need to specify it. Hope the information will help you. If you have nay more problems regarding this then do post back and we will try to solve it.

  5. #5
    Join Date
    Nov 2009
    Posts
    583

    Re: Access a file in a jar

    Hello,
    I agree with the above post, it is correct and I would like to add some more details to it. The manifest contains information by line. Each line consists of the type of information and its value, all separated by the character ":". Each line to be valid, must necessarily end with a return character at the line, so be careful to add that character to the end of the last line of the file.

    - Listed below are some information that can include the obvious (with values of examples):
    - Manifest-Version: 1.0 (Manifest meets specifications 1.0, writing manifestos)
    - Main-Class: classname (from version 1.2 of the manifest specifies the class name to execute the launch of the archive).
    - Implementation-Title: "full package"
    - Implementation-Version: "No version"
    - Implementation-Vendor: "organization selling the product"
    - Specification-Title: "full specification"
    - Specification-Version: "No version"
    - Specification-Vendor: "organization selling the product"

  6. #6
    Join Date
    Nov 2009
    Posts
    333

    Re: Access a file in a jar

    Hello,
    You can not run a command from a script inside a jar. In fact the script is launched by the system shell and it does not take into account the archive (not to my knowledge anyway): the script must be present directly in the file system. The best solution in your case would be to extract this file to a temporary folder and run it from there.

Similar Threads

  1. Replies: 22
    Last Post: 03-05-2012, 02:06 PM
  2. Replies: 3
    Last Post: 21-03-2012, 09:10 AM
  3. Replies: 3
    Last Post: 19-12-2010, 07:57 AM
  4. User cannot access file on file server Windows 2008
    By Wahab4 in forum Windows Server Help
    Replies: 3
    Last Post: 13-12-2010, 05:56 PM
  5. Replies: 3
    Last Post: 11-12-2010, 11:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,796,275.15871 seconds with 17 queries