Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Access a file in a jar

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-03-2010
Member
 
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!
Reply With Quote
  #2  
Old 05-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 05-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 344
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.
Reply With Quote
  #5  
Old 05-03-2010
Member
 
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"
Reply With Quote
  #6  
Old 05-03-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Access a file in a jar"
Thread Thread Starter Forum Replies Last Post
Windows cannot access the specified device path or file. You may not have the appropiate permission to access the item green777 Operating Systems 20 20-10-2011 10:34 PM
Error Deleting File or Folder. Cannot delete (FILE): Access denied FJK MediaCenter 9 23-02-2011 02:57 PM
windows cannot access the specified device path or file. you may not have appropriate permissions to access the item gilsoffer1 Operating Systems 3 19-12-2010 07:57 AM
User cannot access file on file server Windows 2008 Wahab4 Windows Server Help 3 13-12-2010 05:56 PM
Access 2010 file in Access 2007 gives Unrecognized Database Format Roakman MS Office Support 3 11-12-2010 11:45 PM


All times are GMT +5.5. The time now is 03:48 AM.