Get reference to a file adjacent to the executable on Windows and Linux, or inside Contents/Resources/Java on Mac OS X. This will return the local JRE location, whether or not it is the active JRE .
(String name)
| 286 | * JRE location, *whether or not it is the active JRE*. |
| 287 | */ |
| 288 | static public File getContentFile(String name) { |
| 289 | if (processingRoot == null) { |
| 290 | // Get the path to the .jar file that contains Base.class |
| 291 | URL pathURL = |
| 292 | Base.class.getProtectionDomain().getCodeSource().getLocation(); |
| 293 | // Decode URL |
| 294 | String decodedPath; |
| 295 | try { |
| 296 | decodedPath = pathURL.toURI().getSchemeSpecificPart(); |
| 297 | } catch (URISyntaxException e) { |
| 298 | e.printStackTrace(); |
| 299 | return null; |
| 300 | } |
| 301 | |
| 302 | if (decodedPath.contains("/app/bin")) { // This means we're in Eclipse |
| 303 | final File build = new File(decodedPath, "../../build").getAbsoluteFile(); |
| 304 | if (Platform.isMacOS()) { |
| 305 | processingRoot = new File(build, "macosx/work/Processing.app/Contents/Java"); |
| 306 | } else if (Platform.isWindows()) { |
| 307 | processingRoot = new File(build, "windows/work"); |
| 308 | } else if (Platform.isLinux()) { |
| 309 | processingRoot = new File(build, "linux/work"); |
| 310 | } |
| 311 | } else { |
| 312 | // The .jar file will be in the lib folder |
| 313 | File jarFolder = new File(decodedPath).getParentFile(); |
| 314 | if (jarFolder.getName().equals("lib")) { |
| 315 | // The main Processing installation directory. |
| 316 | // This works for Windows, Linux, and Apple's Java 6 on OS X. |
| 317 | processingRoot = jarFolder.getParentFile(); |
| 318 | } else if (Platform.isMacOS()) { |
| 319 | // This works for Java 8 on OS X. We don't have things inside a 'lib' |
| 320 | // folder on OS X. Adding it caused more problems than it was worth. |
| 321 | processingRoot = jarFolder; |
| 322 | } |
| 323 | if (processingRoot == null || !processingRoot.exists()) { |
| 324 | // Try working directory instead (user.dir, different from user.home) |
| 325 | System.err.println("Could not find lib folder via " + |
| 326 | jarFolder.getAbsolutePath() + |
| 327 | ", switching to user.dir"); |
| 328 | processingRoot = new File(""); // resolves to "user.dir" |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | return new File(processingRoot, name); |
| 333 | } |
| 334 | |
| 335 | |
| 336 | static public File getJavaHome() { |
no test coverage detected