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)
| 333 | * JRE location, *whether or not it is the active JRE*. |
| 334 | */ |
| 335 | static public File getContentFile(String name) { |
| 336 | if (processingRoot == null) { |
| 337 | // Get the path to the .jar file that contains Base.class |
| 338 | URL pathURL = |
| 339 | Base.class.getProtectionDomain().getCodeSource().getLocation(); |
| 340 | // Decode URL |
| 341 | String decodedPath; |
| 342 | try { |
| 343 | decodedPath = pathURL.toURI().getSchemeSpecificPart(); |
| 344 | } catch (URISyntaxException e) { |
| 345 | Messages.showError("Missing File", |
| 346 | "Could not access a required file:\n" + |
| 347 | "<b>" + name + "</b>\n" + |
| 348 | "You may need to reinstall Processing.", e); |
| 349 | return null; |
| 350 | } |
| 351 | |
| 352 | if (decodedPath.contains("/app/bin")) { // This means we're in Eclipse |
| 353 | final File build = new File(decodedPath, "../../build").getAbsoluteFile(); |
| 354 | if (Platform.isMacOS()) { |
| 355 | processingRoot = new File(build, "macos/work/Processing.app/Contents/Java"); |
| 356 | } else if (Platform.isWindows()) { |
| 357 | processingRoot = new File(build, "windows/work"); |
| 358 | } else if (Platform.isLinux()) { |
| 359 | processingRoot = new File(build, "linux/work"); |
| 360 | } |
| 361 | } else { |
| 362 | // The .jar file will be in the lib folder |
| 363 | File jarFolder = new File(decodedPath).getParentFile(); |
| 364 | if (jarFolder.getName().equals("lib")) { |
| 365 | // The main Processing installation directory. |
| 366 | // This works for Windows, Linux, and Apple's Java 6 on OS X. |
| 367 | processingRoot = jarFolder.getParentFile(); |
| 368 | } else if (Platform.isMacOS()) { |
| 369 | // This works for Java 8 on OS X. We don't have things inside a 'lib' |
| 370 | // folder on OS X. Adding it caused more problems than it was worth. |
| 371 | processingRoot = jarFolder; |
| 372 | } |
| 373 | if (processingRoot == null || !processingRoot.exists()) { |
| 374 | // Try working directory instead (user.dir, different from user.home) |
| 375 | System.err.println("Could not find lib folder via " + |
| 376 | jarFolder.getAbsolutePath() + |
| 377 | ", switching to user.dir"); |
| 378 | processingRoot = new File(""); // resolves to "user.dir" |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | return new File(processingRoot, name); |
| 383 | } |
| 384 | |
| 385 | |
| 386 | static public File getJavaHome() { |
no test coverage detected