From f182e87ee175dd7aa970a6ec659c9ef3eebfe6fb Mon Sep 17 00:00:00 2001 From: Colin But Date: Sun, 10 Jul 2016 20:51:52 +0100 Subject: [PATCH] fixed app launch --- .../java/com/iluwatar/pageobject/App.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/page-object/src/main/java/com/iluwatar/pageobject/App.java b/page-object/src/main/java/com/iluwatar/pageobject/App.java index 67b3f947b..235eedd25 100644 --- a/page-object/src/main/java/com/iluwatar/pageobject/App.java +++ b/page-object/src/main/java/com/iluwatar/pageobject/App.java @@ -69,25 +69,21 @@ public final class App { */ public static void main(String[] args) { - String currentWorkingDir = System.getProperty("user.dir"); - File applicationFile = new File(currentWorkingDir - + "/page-object/src/main/resources/sample-ui/login.html"); + try { + File applicationFile = new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath()); - // should work for unix like OS (mac, unix etc...) - if (Desktop.isDesktopSupported()) { - try { + // should work for unix like OS (mac, unix etc...) + if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(applicationFile); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - // java Desktop not supported - above unlikely to work for Windows so try following instead... - try { + + } else { + // java Desktop not supported - above unlikely to work for Windows so try following instead... Runtime.getRuntime().exec("cmd.exe start " + applicationFile); - } catch (IOException e) { - e.printStackTrace(); } + } catch (IOException ex) { + ex.printStackTrace(); } + } }