MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

"Could not launch browser" when launched with exe generated by Launch4J #312

Open Gintasz opened 6 years ago

Gintasz commented 6 years ago

I have a Java app that's using simple JBrowserDriver setup. It works fine when launched as a jar. Now, I need administrator privileges for whole other feature in my app, so I wrap it in an exe generated with Launch4J.

Thing is, I get "could not launch browser" when I'm using wrapped exe to launch my app.

                Settings settings = Settings.builder()
                        .userAgent(new UserAgent(UserAgent.Family.MOZILLA, "", "Mac", "Intel Mac OS X 10.12",
                                "5.0 (Macintosh)",
                                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"))
                        .socketTimeout(20000)
                        .connectTimeout(20000)
                        .connectionReqTimeout(20000)
                        .ajaxResourceTimeout(20000)
                        .javaOptions("-Dquantum.verbose=true", "-Dprism.verbose=true", "-verbose:class")
                        .build();
                WebDriver driver = new JBrowserDriver(settings);
                ((JBrowserDriver) driver).init();

There is a lot of spam in log due to verbose mode, but here are the final lines before exception:

[2017-11-25T13:03:04.520] [Loaded java.text.FieldPosition from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] [2017-11-25T13:03:04.520] [Loaded java.util.Date from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] [2017-11-25T13:03:04.521] [Loaded java.text.AttributedCharacterIterator$Attribute from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] [2017-11-25T13:03:04.521] [Loaded java.text.Format$Field from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] [2017-11-25T13:03:04.521] [Loaded java.text.MessageFormat$Field from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] [2017-11-25T13:03:04.522] Error: Could not find or load main class com.machinepublishers.jbrowserdriver.JBrowserDriverServer [2017-11-25T13:03:04.522] [Loaded java.lang.Shutdown from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] [2017-11-25T13:03:04.523] [Loaded java.lang.Shutdown$Lock from C:\Program Files\Java\jre1.8.0_152\lib\rt.jar] WebDriverPoolManager org.openqa.selenium.WebDriverException: Could not launch browser. Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: '9C9A8', ip: '80.209.231.203', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_152' Driver info: driver.version: JBrowserDriver at com.machinepublishers.jbrowserdriver.Util.handleException(Util.java:139)

What's wrong? Here is my launch4j config:

<launch4jConfig>
  <dontWrapJar>false</dontWrapJar>
  <headerType>console</headerType>
  <jar>/Users/gintas/workspace/appname/build/libs/appname-unobfuscated.jar</jar>
  <outfile>/Users/gintas/workspace/appname/appname_unobfuscated.exe</outfile>
  <errTitle>Please download Java Runtime Environment!</errTitle>
  <cmdLine></cmdLine>
  <chdir></chdir>
  <priority>normal</priority>
  <downloadUrl>http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html</downloadUrl>
  <supportUrl></supportUrl>
  <stayAlive>false</stayAlive>
  <manifest>/Users/gintas/workspace/appname/appname</manifest>
  <icon>/Users/gintas/workspace/appname/appname_icon</icon>
  <singleInstance>
    <mutexName>appname_mutex</mutexName>
    <windowTitle></windowTitle>
  </singleInstance>
  <jre>
    <path></path>
    <bundledJre64Bit>false</bundledJre64Bit>
    <minVersion>1.7.0</minVersion>
    <maxVersion></maxVersion>
    <jdkPreference>preferJre</jdkPreference>
  </jre>
  <messages>
    <startupErr>An error occurred while starting the application.</startupErr>
    <bundledJreErr>This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted.</bundledJreErr>
    <jreVersionErr>This application requires a Java Runtime Environment with minimum version</jreVersionErr>
    <launcherErr>The registry refers to a nonexistent Java Runtime Environment installation or the runtime is corrupted.</launcherErr>
    <instanceAlreadyExistsMsg>An application instance is already running.</instanceAlreadyExistsMsg>
  </messages>
</launch4jConfig>
Gintasz commented 6 years ago

There are some kind of classpath settings in launch4j, that might be relevant, but I have no idea how to fix this.

screen shot 2017-11-25 at 15 18 43
efernandesng commented 6 years ago

It looks that you need create a fat jar with all dependencies before create a exe.