• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem with the path inside a jar-file

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everybody,

actually i am coding a small tool. i am using ide eclipse. there i have built a project with a few classes and in the root of the project there is folder containing several .txt files.
if i read them with my application in eclipse, there is no problem. but then i built a jar file (using fat jar plugin for eclipse). now the tool can not find the .txt files anymore (even if they are present in the jar-file).
i looked up the internet for a solution but could not find anything.

can someone please help me?

Project:

controller.Application.java --> uses another class "InOut"

io.InOut.java --> this one acceses the files in the folder below

sql_templates/ --> Folder
sql_templates/generateCode.txt ---> many files like this


thanks a lot
kilia
 
Marshal
Posts: 80619
469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try putting the jar file into another folder, unzipping it and exploring its file structure to make sure the folders are where you want them.

I went into Eclipse->help and looked for jar files and this is what comes up

Creating a new JAR file

To create a new JAR file in the workbench:

1. In the Package Explorer, you can optionally pre-select one or more Java elements to export. (These will be automatically selected in the Opens the JAR export wizard JAR Package Specification wizard page, described in Step 4.)
2. Either from the context menu or from the menu bar's File menu, select Export.
3. Expand the Java node and select JAR file. Click Next.
4. In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.
5. Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source files and resources. Note: Selected resources are exported in both cases.
6. In the Select the export destination field, either type or click Browse to select a location for the JAR file.
7. Select or clear the Compress the contents of the JAR file checkbox.
8. Select or clear the Overwrite existing files without warning checkbox. If you clear this checkbox, then you will be prompted to confirm the replacement of each file that will be overwritten.
9. Note: The overwrite option is applied when writing the JAR file, the JAR description, and the manifest file.
10. You have two options:
* Click Finish to create the JAR file immediately.
* Click Next to use the JAR Packaging Options page to set advanced options, create a JAR description, or change the default manifest.

See whether No 4 is of any use to you; I think your text files count as a "resource" to export.

The Java Tutorials have a section about jar files; try the link to updating a JAR file.
 
Rancher
Posts: 5114
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does your "tool" find the .txt files?
Are you using the getResource() method? This uses the classloader which knows how to find things in a jarfile, in a folder/subfolder or on a server.

Since jar files are VERY similiar to zip files, you can look at the contents of a jar file by using a zip file reader like WinZip, you wouldn't have to extract contents to see what's there.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic