Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "NoClassDefFoundError" Exception when executing Test on Ubuntu 16.04 #16

Open
gaurabhi1986 opened this issue Oct 24, 2016 · 15 comments

Comments

@gaurabhi1986
Copy link

While using this API I am getting below exception.

Can you please let me know How can I resolve this exception.

java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at com.browserstack.local.LocalBinary.downloadBinary(LocalBinary.java:96)
at com.browserstack.local.LocalBinary.getBinary(LocalBinary.java:57)
at com.browserstack.local.LocalBinary.(LocalBinary.java:26)
at com.browserstack.local.Local.start(Local.java:57)

Thanks,
Abhishek

@gaurabhi1986 gaurabhi1986 changed the title Getting "NoClassDefFoundError" Exception Getting "NoClassDefFoundError" Exception when executing Test on Ubuntu 16.04 Oct 24, 2016
@gaurabhi1986
Copy link
Author

@tr4n2uil can you please resolve this issue.

@tr4n2uil
Copy link
Contributor

tr4n2uil commented Nov 3, 2016

@gaurabhi1986 Please check pom.xml and ensure all dependencies are installed properly. Check out the following snippet from pom.xml in this repo:

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160212</version>
        </dependency>
    </dependencies>

I believe the error is coming since you haven't installed commons-io. Please check.

@gaurabhi1986
Copy link
Author

Hi @tr4n2uil

I have all the required dependencies installed , still getting this error. please solve this issue.

Thanks,
Abhishe

@tr4n2uil
Copy link
Contributor

tr4n2uil commented Nov 4, 2016

Please follow these steps and let us know if it worked:

  1. Clone this fork.
  2. Switch to example branch.
  3. Run mvn compile && mvn exec:java -Dexec.mainClass=example.BrowserStackLocalExample

This will run the example code which shows how to use com.browserstack.local.Local

@gaurabhi1986
Copy link
Author

Hi @tr4n2uil

I am using this example as a reference to start Browserstack local, but still facing same problem, have modified pom.xml but nothing is working same error coming each time.

Thanks,
Abhishek

@tr4n2uil
Copy link
Contributor

tr4n2uil commented Nov 7, 2016

Can you try mvn clean and then mvn compile && mvn exec:java -Dexec.mainClass=example.BrowserStackLocalExample as earlier ?

Also post the output (with error, if any) please.

@gaurabhi1986
Copy link
Author

gaurabhi1986 commented Nov 8, 2016

Hi @tr4n2uil

I am getting below exception in you example branch 👍

[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building browserstack-local-java 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ browserstack-local-java ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1012)
at com.browserstack.local.Local.runCommand(Local.java:182)
at com.browserstack.local.Local.start(Local.java:66)
at example.BrowserStackLocalExample.main(BrowserStackLocalExample.java:31)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.715 s
[INFO] Finished at: 2016-11-08T16:05:00+11:00
[INFO] Final Memory: 14M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project browserstack-local-java: An exception occured while executing the Java class. null: InvocationTargetException: NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@tr4n2uil
Copy link
Contributor

tr4n2uil commented Nov 8, 2016

Seems like didn't set your access key in environment.

Run the following, if linux/mac

export BROWSERSTACK_ACCESS_KEY=<your access key here>

or if windows then

set BROWSERSTACK_ACCESS_KEY=<your access key here>

then run as before

mvn clean && mvn compile && mvn -e exec:java -Dexec.mainClass=example.BrowserStackLocalExample

Again, post the output (with error, if any) please.

@gaurabhi1986
Copy link
Author

Hi @tr4n2uil,

Now getting this exception.

[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building browserstack-local-java 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ browserstack-local-java ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:433)
at org.json.JSONObject.(JSONObject.java:195)
at org.json.JSONObject.(JSONObject.java:319)
at com.browserstack.local.Local.start(Local.java:80)
at example.BrowserStackLocalExample.main(BrowserStackLocalExample.java:32)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.107 s
[INFO] Finished at: 2016-11-08T16:59:50+11:00
[INFO] Final Memory: 15M/227M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project browserstack-local-java: An exception occured while executing the Java class. null: InvocationTargetException: A JSONObject text must begin with '{' at 1 [character 2 line 1] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@tr4n2uil
Copy link
Contributor

tr4n2uil commented Nov 8, 2016

Cool. Pushed a minor change. Can you pull and re-run ?

git pull origin example

mvn clean && mvn compile && mvn -e exec:java -Dexec.mainClass=example.BrowserStackLocalExample

Again, post the output with error, if any.

@gaurabhi1986
Copy link
Author

Hi @tr4n2uil,

Now getting this 👍

C:\Users\abhishek.gaur\browserstack-local-java>mvn compile && mvn -e exec:java -Dexec.mainClass=example.BrowserStackLocalExample
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building browserstack-local-java 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ browserstack-local-java ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\abhishek.gaur\browserstack-local-java\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ browserstack-local-java ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 4 source files to C:\Users\abhishek.gaur\browserstack-local-java\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.300 s
[INFO] Finished at: 2016-11-08T17:42:50+11:00
[INFO] Final Memory: 18M/170M
[INFO] ------------------------------------------------------------------------
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building browserstack-local-java 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ browserstack-local-java ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:433)
at org.json.JSONObject.(JSONObject.java:195)
at org.json.JSONObject.(JSONObject.java:319)
at com.browserstack.local.Local.start(Local.java:82)
at example.BrowserStackLocalExample.main(BrowserStackLocalExample.java:32)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.869 s
[INFO] Finished at: 2016-11-08T17:43:29+11:00
[INFO] Final Memory: 15M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project browserstack-local-java: An exception occured while executing the Java class. null: InvocationTargetException: A JSONObject text must begin with '{' at 1 [character 2 line 1] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project browserstack-local-java: An exception occured while executing the Java class. null
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:433)
at org.json.JSONObject.(JSONObject.java:195)
at org.json.JSONObject.(JSONObject.java:319)
at com.browserstack.local.Local.start(Local.java:82)
at example.BrowserStackLocalExample.main(BrowserStackLocalExample.java:32)
... 6 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@gaurabhi1986
Copy link
Author

Hi @tr4n2uil ..

Please resolve this issues...

@vedharish
Copy link
Contributor

Hey @gaurabhi1986

I just tested the example branch on the clone on Ubuntu 16.04 vagrant image. Things are working fine for me.
Also, note that the BROWSERSTACK_USER env variable was used instead of BROWSERSTACK_USERNAME, only in the example. We pushed a commit for that, but anyways that error doesn't seem relevant to your case.

In your case, the issue seems to be with the BrowserStackLocal binary connection.
Relevant change - environment variable BROWSERSTACK_ACCESS_KEY. Make sure that you did export and not just set the variable (It works smoothly in my case).

And to resolve this faster, without delays, just drop an email to [email protected] with the subject Getting "NoClassDefFoundError" Exception when executing Test on Ubuntu 16.04 and make sure you mention if you are behind a proxy/firewall. Hoping to resolve this quickly.

@gaurabhi1986
Copy link
Author

Hi @tr4n2uil

I am not exporting env variable I am simply assigning string value to username and key variables.

Same code sample is working when I set bsLocalArgs.put("binarypath", "/browserstack/BrowserStackLocal");

but it does not work when i did not set localbinary path.

Can you please let me know do I need to set any proxy or something.

@punitx
Copy link
Collaborator

punitx commented Jun 15, 2017

@gaurabhi1986 Is this still an issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants