-1

i hv created the .jar file by building my project in netbeans.

  • The .jar file exist in "dist/myproject.jar". But when i move it to any other system will it find the paths specified for images etc in project?

    • As i am giving the paths like (C:/Users/Lucky/Documents/NetBeansProjects/CoverageAnalyzer/src/coverageanalyzer/icons/icon.png). OR When i write path just to approach root directory as (icons/icon.png), so then also?
  • Summary: What is the actual way that i can write/copy my .jar file to any other system without spoiling the paths and program run correctly on any other system. Thanks in advance.help will be appriciated

2 Answers2

1

You can use one of the following approaches:

  1. Use relative paths (relative to the executable file location) instead of absolute paths.
  2. Use paths under a known absolute path (an installation folder, path from environment variable / configuration file / registry key, the user's directory (user.home) etc.)
  3. Use resources embeded into your jar. See Class.getResource() and Class.getResourceAsStream()

Note that you should consider cross-platform (Windows/Linux/Mac) and resource hiding issues when selecting a suitable approach.

Community
  • 1
  • 1
Elist
  • 5,313
  • 3
  • 35
  • 73
0

The solution is to put the auxiliary files as resources into to jar. The program must then load them from the class path instead of the file system.

Have a look at Class.getResourceAsStream.

Henry
  • 42,982
  • 7
  • 68
  • 84