Unable to load com.mysql.jdbc.Driver - mysql

when I run ant for a Testng application, I am unable to load com.mysql.jdbc.Driver.
Below is the exception thrown.
[testng] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[testng] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[testng] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[testng] at java.security.AccessController.doPrivileged(Native Method)
Thanks and regards,
Sreekanth

The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDE's.
That environment variable is in real world also considered a poor practice since it breaks portability. It's only "useful" for Sun to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments. In real world, batch/shell files are preferred.
If you're using an IDE, The classpath is called the "build path" (it represents both compiletime and runtime classpath). You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget the whole CLASSPATH environment variable.
For command prompt,
You have to put the full path to the jarfile in the classpath (including the filename):
.;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar
As Hippo said, you have to restart cmd after changing that. If it doesn't work, launch your program like this:
java -cp ".;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar"
my.class.Name

Related

Execute testNG in CMD prompt

Unable to execute testNG in CMD prompt.
I'm getting this error:
java.lang.ClassNotFoundException: com.google.gson.JsonObject
I have all the jars in my build path. gson-2.8.2.jar and all the selenium supported jars and even testng jars.
java.lang.NoClassDefFoundError: com/google/gson/JsonObject Caused by:
java.lang.ClassNotFoundException: com.google.gson.JsonObject
Command used to run:
java -cp bin;jarslib/* org.testng.TestNG testng.xml
All the jars in my JarsLib folder
I found the solution, I've added into my resource but not added into my environment variable. Once I added, it's working fine.

ChromeDriver setSystem property issue

when I'm trying to run test I have issue as on screenshot, where am I wrong?
thx
"C:\Program Files\Java\jdk1.8.0_11\bin\java" -ea -Didea.launcher.port=7537 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\plugins\testng\lib\testng-plugin.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_11\jre\lib\ext\zipfs.jar;C:\Users\vol.7\Downloads\aaaaaa\src\main\resources\target\test-classes;C:\Users\vol.7\Downloads\aaaaaa\target\classes;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.44.0\selenium-chrome-driver-2.44.0.jar;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\2.44.0\selenium-remote-driver-2.44.0.jar;C:\Users\vol.7\.m2\repository\cglib\cglib-nodep\2.1_3\cglib-nodep-2.1_3.jar;C:\Users\vol.7\.m2\repository\com\google\code\gson\gson\2.3\gson-2.3.jar;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-api\2.44.0\selenium-api-2.44.0.jar;C:\Users\vol.7\.m2\repository\org\apache\httpcomponents\httpclient\4.3.4\httpclient-4.3.4.jar;C:\Users\vol.7\.m2\repository\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.jar;C:\Users\vol.7\.m2\repository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;C:\Users\vol.7\.m2\repository\commons-codec\commons-codec\1.6\commons-codec-1.6.jar;C:\Users\vol.7\.m2\repository\com\google\guava\guava\18.0\guava-18.0.jar;C:\Users\vol.7\.m2\repository\net\java\dev\jna\jna\3.4.0\jna-3.4.0.jar;C:\Users\vol.7\.m2\repository\net\java\dev\jna\platform\3.4.0\platform-3.4.0.jar;C:\Users\vol.7\.m2\repository\org\testng\testng\6.9.9\testng-6.9.9.jar;C:\Users\vol.7\.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\vol.7\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;C:\Users\vol.7\.m2\repository\com\beust\jcommander\1.48\jcommander-1.48.jar;C:\Users\vol.7\.m2\repository\org\apache\ant\ant\1.7.0\ant-1.7.0.jar;C:\Users\vol.7\.m2\repository\org\apache\ant\ant-launcher\1.7.0\ant-launcher-1.7.0.jar;C:\Users\vol.7\.m2\repository\org\yaml\snakeyaml\1.15\snakeyaml-1.15.jar;C:\Users\vol.7\.m2\repository\org\beanshell\bsh\2.0b4\bsh-2.0b4.jar;C:\Users\vol.7\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.44.0\selenium-firefox-driver-2.44.0.jar;C:\Users\vol.7\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\vol.7\.m2\repository\org\apache\commons\commons-exec\1.1\commons-exec-1.1.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\plugins\testng\lib\testng.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.testng.RemoteTestNGStarter -port 54806 -usedefaultlisteners false -socket54807 -temp C:\Users\vol.7\AppData\Local\Temp\idea_testng36.tmp
org.testng.TestNGException: Cannot instantiate class Aaas at
org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at
org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:382)
at
org.testng.internal.ClassHelper.createInstance(ClassHelper.java:295)
at
org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:118)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:183) at
org.testng.internal.TestNGClassFinder.(TestNGClassFinder.java:128)
at org.testng.TestRunner.initMethods(TestRunner.java:416) at
org.testng.TestRunner.init(TestRunner.java:242) at
org.testng.TestRunner.init(TestRunner.java:212) at
org.testng.TestRunner.(TestRunner.java:166) at
org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:143)
at
org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:272)
at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:587)
at org.testng.SuiteRunner.init(SuiteRunner.java:161) at
org.testng.SuiteRunner.(SuiteRunner.java:114) at
org.testng.TestNG.createSuiteRunner(TestNG.java:1290) at
org.testng.TestNG.createSuiteRunners(TestNG.java:1277) at
org.testng.TestNG.runSuitesLocally(TestNG.java:1131) at
org.testng.TestNG.run(TestNG.java:1048) at
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112) at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205) at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176) at
org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125) 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:483) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.reflect.InvocationTargetException at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at
org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
... 27 more Caused by: java.lang.IllegalStateException: The path to
the driver executable must be set by the webdriver.chrome.driver
system property; for more information, at
com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117)
at Aaas.(Aaas.java:11) ... 32 more
Process finished with exit code 0
In your code it looks like you did 2 mistakes.
First thing...
Please remove the instantiation of "new ChromeDriver()" when a reference of type WebDriver created in class.
Instead create a referece:
public WebDriver driver;
Then instantiate the chrome driver inside the test case-->
#Test
public void testMethod(){
//Here, Before the instantiation just use setProperty method
System.setProperty("key","path to chrome driver.exe");
driver=new ChromeDriver();
}
and the Second thing is...
make sure the relative path is correct to chromedriver.exe file...
Use absolute path to the chrome driver.
You're creating the new ChromeDriver in your (implicit) constructor before you're calling: System.setProperty("webdriver.chrome.driver", ...)
You need to set the property before creating any Drivers (same applies to IE, Opera, etc.)
One approach is to create a static { ... } block and move your setting of System properties there. That'll get called before you create your Driver.
It looks like you are not given complete chromediver.exe path. More over over calling chrome driver before system.set property. please set system property first then call chrome driver..
System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
Thank You,
Murali
You haven't set a location for the chromedriver binary. Edit the configuration of your test by clicking on the drop down box in the top bar. Then add to your VM options a path for the chromedriver binary:
-Dwebdriver.chrome.driver=<ABSOLUTE_PATH_TO>/chromedriver
Since you are using a maven project you may find this maven plugin useful:
https://github.com/Ardesco/selenium-standalone-server-plugin
It will download the driver binaries for you and set up the correct system properties when running your tests through maven. There is a template that uses it here that you can use as an example of how to get it configured:
https://github.com/Ardesco/Selenium-Maven-Template
*Note* Running the test through intelliJ is not the same as running it through maven. System properties that are only set through maven will not have been set in IntelliJ when you run a test through the IDE. This is why you need to edit your test configuration if you have already set the correct System Properties through maven.

Problems with Clojurescript quickstart -- build fails

I'm trying to follow the Clojurescript Quick-Start
I have downloaded the Clojurescript jar as described in the Quick-Start guide. I have verified that it has the appropriate size (about 19M). I have created the files. But when I try to build using the command:
java -cp cljs.jar:src clojure.main build.clj
Java returns the following stacktrace:
Exception in thread "main" java.io.FileNotFoundException: Could not locate cls/build/api__init.class or cls/build/api.clj on classpath., compiling:(/Users/jnedzel/Documents/prj/closurescript/quickstart/hello_world/build.clj:1:1)
at clojure.lang.Compiler.load(Compiler.java:7249)
at clojure.lang.Compiler.loadFile(Compiler.java:7175)
at clojure.main$load_script.invoke(main.clj:275)
at clojure.main$script_opt.invoke(main.clj:337)
at clojure.main$main.doInvoke(main.clj:421)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:379)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.io.FileNotFoundException: Could not locate cls/build/api__init.class or cls/build/api.clj on classpath.
Any ideas?
TL;DR: There's a typo in build.clj
Full explanation
As of the Quick-Start, the file build.clj should have the following content:
(require 'cljs.build.api)
(cljs.build.api/build "src" {:output-to "out/main.js"})
The error message says Could not locate cls/build/api__init.class. When the clojure compiler compiles a ns, a loader classfile is generated with the name my/domain/lib__init.class. That's the class that will be loaded given (require 'my.domain.lib).
In the case of cljs.build.api, that would be cljs/build/api__init.class. But it is trying to load cls/build/api__init.class instead, so you have a typo there.

How do I configure CI hudson with PHPunit and how do I run phpunit using hudson?

I am getting following error mentioned below. Help is much needed for this...
kindly go through the errors.
Started by an SCM change
Updating https://suppliesguys.unfuddle.com/svn/suppliesguys_frontend2/Frontend-Texity/src
U sites\all\modules\print\print_pdf\print_pdf.pages.inc
At revision 1134
[workspace] $ sh -xe C:\WINDOWS\TEMP\hudson6292587174545072503.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory "E:\Projects\Hudson\.hudson\jobs\TSG\workspace"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:149)
at hudson.Proc$LocalProc.<init>(Proc.java:121)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:636)
at hudson.Launcher$ProcStarter.start(Launcher.java:271)
at hudson.Launcher$ProcStarter.join(Launcher.java:278)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:83)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:584)
at hudson.model.Build$RunnerImpl.build(Build.java:174)
at hudson.model.Build$RunnerImpl.doRun(Build.java:138)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:416)
at hudson.model.Run.run(Run.java:1244)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:122)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 17 more
Publishing Javadoc
Publishing Clover coverage report...
No Clover report will be published due to a Build Failure
[xUnit] Starting to record.
[xUnit] [PHPUnit] - Use the embedded style sheet.
[xUnit] [ERROR] - No test report file(s) were found with the pattern 'build/logs/phpunit.xml' relative to 'E:\Projects\Hudson\.hudson\jobs\TSG\workspace' for the testing framework 'PHPUnit'. Did you enter a pattern relative to the correct directory? Did you generate the result report(s) for 'PHPUnit'?
[xUnit] Stopping recording.
Finished: FAILURE
It looks like you are using the "Execute shell" build step on a windows system instead of the "Execute Windows batch command" build step. Windows doesn't normally have 'sh', so the former won't work.
Looks like you have a couple of problems:
FATAL: command execution failed java.io.IOException: Cannot run program "sh" (in directory "E:\Projects\Hudson.hudson\jobs\TSG\workspace"):
The user that's running the Hudson job doesn't have the "sh" command in its path, so it can't run shell scripts. Adding /bin to the $PATH of the Hudson user should fix this.
[xUnit] [ERROR] - No test report file(s) were found with the pattern 'build/logs/phpunit.xml' relative to 'E:\Projects\Hudson.hudson\jobs\TSG\workspace' for the testing framework 'PHPUnit'.
This is probably a result of the previous error; the build just didn't get far enough to run the PHPUnit tests.
'sh' is for linux implementations. Both '.exe' and 'bat' files are used in windows. Are you trying to setup and run Hudson on windows or linux?

How to register a JDBC driver using jruby-complete.jar?

I'm trying to write a script that is executed with the jruby-complete.jar like so:
java -cp derby.jar; -Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver -jar jruby-complete.jar -S my_script.rb
I'm using JVM 1.6.0_11 and JRuby 1.4.
In my jruby script I attempt to connect to the database like this.
connection = Java::com.sql.DriverManager.getConnection("jdbc:derby:path_to_my_DB")
This throws a java.sql.SQLException: "No suitable driver found" exception.
I've tried manually loading the driver into the class loader using Class.forName which gives me the same error.
It looks like to me that the class loader being used by the DriverManager is not the same as the current thread's. I've tried setting the current thread's class loader using:
JThread = java.lang.Thread
...
class_loader = JavaLang::URLClassLoader.new(
[JavaLang::URL.new("jar:file:/derby.jar!/")].to_java(
JavaLang::URL),JRuby.runtime.jruby_class_loader)
JThread.currentThread().setContextClassLoader(class_loader )
But this doesn't help.
Any ideas?
OK I downloaded jruby-complete.jar and had a go....
This seems to work for me:
java -classpath c:\ruby\db-derby-10.5.3.0-bin\lib\derby.jar;jruby-complete-1.4.0.jar org.jruby.Main -S derby.rb
When using the -jar switch, the -classpath option is ignored (maybe the CLASSPATH shell var is too). But on the above line, we put both required jars on the class path and pass the class name to execute (i.e. org.jruby.Main). The script being passed in is as per my other answer.
Another option (which I have not tried) would be to alter the jruby-complete.jar manifest file to specify as classpath, as described here:
Adding Classes to the JAR File's Classpath
First, make sure your driver jar is not corrupted (this made me waste a couple of days one time).
Second, read this about JRuby/Java classloade: JRuby Wiki
Third (because I haven't played with "jruby-complete") try this simple script and then see if you can adapt as you need.
require 'java'
require 'C:\ruby\db-derby-10.5.3.0-bin\lib\derby.jar' # adjust for your machine
include_class "java.sql.DriverManager"
derby = org.apache.derby.jdbc.EmbeddedDriver.new
connection = DriverManager.getConnection("jdbc:derby:derbyDB;create=true")