Establishing a Connection to Derby - derby

I'm trying to establish a connection to a Derby database using the code below.
static {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (Exception e) {e.printStackTrace();}
}
However, when I run it, I get the following error:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
I understand that it cannot find the Derby driver, and is a classpath error. However, I have copied all the Derby .jar files into my project's /lib folder, and I don't understand what is missing. Help anyone?

Perhaps your project's lib folder isn't in the classpath.
The error says that derbyclient.jar was not found in the classpath.

Related

ExtentReports: HtmlReporter not starting when running an executable jar file created using maven-assembly-plugin

I am trying to execute my test cases programmatically using TestNG. The virtual suite file is executing fine. But, the Extent Report is not being generated.
Getting the following exception stacktrace:
java.lang.IllegalStateException: No reporters were started. Atleast 1 reporter must be started to create tests.
at com.aventstack.extentreports.Report.createTest(Report.java:69)
at com.aventstack.extentreports.ExtentReports.createTest(ExtentReports.java:241)
at com.aventstack.extentreports.ExtentReports.createTest(ExtentReports.java:254)
at com.automation.service.impl.ExtentReportService.setParentExtentTest(ExtentReportService.java:56)
at com.automation.service.impl.ExtentReportService.startTest(ExtentReportService.java:64)
at com.automation.tests.BaseTest.beforeMethod(BaseTest.java:160)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:520)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Right now, I have set my report to generate at the following location:
E:/selenium/reports/extent-reports/
And I am saving my screenshots in my root folder by the string: "./" which basically is storing the screenshots in E:.
Another observation:
I ran mvn clean install -DskipTests=true from command line.
After that I switched to the target folder and ran the following command: java -jar jar-file-name.jar
Looks like every test cases is failing because of the IllegalStateException it is throwing.
But the screenshots were being captured in the target folder, which technically should be stored in the root fodler.
I tried to change locations of the report and the screenshots. Also let me share the code snipped of my ExtentReportService class:
private static void initializeExtentReport(Configuration config) {
if (extent == null) {
extent = new ExtentReports();
htmlReporter = new ExtentHtmlReporter(getReportName(config));
ClassLoader classLoader = ExtentReportService.class.getClassLoader();
File extentConfigFile = new File(classLoader.getResource("extent-config.xml").getFile());
htmlReporter.loadXMLConfig(extentConfigFile);
extent.attachReporter(htmlReporter);
extent.setSystemInfo("Environment", config.getAutomationServer());
}
}
Thanks in advance for the efforts.
This issue got fixed with the other issue I was having.
So, the main problem I was having was loading the extent-config.xml file. Thus, I changed the location for loading the extent-config.xml file as follows:
File extentConfigFile = new File(classLoader.getResource("extent-config.xml").getFile());
to
File extentConfigFile = new File("./classes/extent-config.xml");
In this manner, the test cases will execute smoothly.

Run generated jar file in apache flink

At the moment I'm trying to run my first flink application. I already tested the java file (KMeans.java) in the IDE and it works perfectly but I can't handle to get this java file run as an jar in command line.
The build was successfully created with mvn clean package.
But if I run my jar file in command line flink run -c KMeans name.jar
this error message appears:
The program finished with the following exception:
org.apache.flink.client.program.ProgramInvocationException: The
program's entry point class 'KMeans' was not found in the jar file.
at
org.apache.flink.client.program.PackagedProgram.loadMainClass(PackagedProgram.java:617)
at
org.apache.flink.client.program.PackagedProgram.(PackagedProgram.java:199)
at
org.apache.flink.client.cli.CliFrontend.buildProgram(CliFrontend.java:856)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:206)
at
org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1044)
at
org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1120)
at java.security.AccessController.doPrivileged(Native Method) at
javax.security.auth.Subject.doAs(Subject.java:422) at
org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1754)
at
org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
at
org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1120)
Caused by: java.lang.ClassNotFoundException: KMeans at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:348) at
org.apache.flink.client.program.PackagedProgram.loadMainClass(PackagedProgram.java:614)
... 10 more
So I looked up my generated target folder and there is a KMeans.class file in the classes folder. So I'm doing this wrong?
You need to specify the full class name, e.g., org.apache.flink.examples.java.clustering.KMeans.
Note that you only need to use the -c flag if the JAR file doesn't specify the class to run in its manifest.

HiveServer Class Not Found Exception

I'm trying to run hive from the command prompt it is working absolutely fine. But when I try running hiveserver using "hive --service hiveserver" command, I'm getting the following exception.
Starting Hive Thrift Server
Exception in thread "main" java.lang.ClassNotFoundException: org.apache.hadoop.hive.service.HiveServer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
So I then tried with the command "hive --service hiveserver2"; still I'm not finding any solution.
Can anybody please suggest a solution for this problem.
May be another process (another hiveserver) already listening on port 10000.
can you check it by :
netstat -ntulp | grep ':10000' to see it and if found then kill the process.
Otherwise start the server on another port.
By the way which version you are using ?
This error occurred to me when it can't find hive-service-*.jar in hadoop classpath. Just copy the hive-service-*.jar to your hadoop lib folder or export classpath in hadoop-env.sh. I have mentioned how to add classpath below.
Add this line in hadoop-env.sh:
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/usr/local/hive/lib/hive-*.jar
I have mentioned the path for hive as /usr/local/hive since i have hive installed at that location. Change it to point to your hive installation.

java.lang.ClassNotFoundException: org.codehaus.jettison.mapped.MappedXMLOutputFactory

I am getting java.lang.ClassNotFoundException: org.codehaus.jettison.mapped.MappedXMLOutputFactory error while running mule application. I checked jettison-1.1.jar jar is already there in my application folder lib directory but still I am getting this error.
I am getting this error while initialising Spring batch job repository.
java.lang.ClassNotFoundException: org.codehaus.jettison.mapped.MappedXMLOutputFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:36)
at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.init(XStreamExecutionContextStringSerializer.java:67)
at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.afterPropertiesSet(XStreamExecutionContextStringSerializer.java:62)
at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.afterPropertiesSet(JobRepositoryFactoryBean.java:182)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
You need to add jettison.jar file to your project.
Download from here

Apache Oozie throws classnotfound exception while creating mysql DB

I am trying to use mysql DB with apache OOzie.
my $OOZIE_HOME is
-bash: /opt/oozie_install/oozie-3.3.0-cdh4.2.2: Is a directory
But I copied mysql-connector-java-5.1.29-bin.jar in almost every possible places.
Like I copied it inside
/opt/oozie_install/oozie-3.3.0-cdh4.2.2
/opt/oozie_install/oozie-3.3.0-cdh4.2.2/libs
/opt/oozie_install/oozie-3.3.0-cdh4.2.2/libtools
/usr/lib/jvm/jdk/libs
/user/home/hadoop/
But I am still getting ClassnotFoundException.
java.lang.Exception: Could not connect to the database: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.oozie.tools.OozieDBCLI.validateConnection(OozieDBCLI.java:473)
at org.apache.oozie.tools.OozieDBCLI.createDB(OozieDBCLI.java:179)
at org.apache.oozie.tools.OozieDBCLI.run(OozieDBCLI.java:118)
at org.apache.oozie.tools.OozieDBCLI.main(OozieDBCLI.java:64)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.apache.oozie.tools.OozieDBCLI.createConnection(OozieDBCLI.java:462)
at org.apache.oozie.tools.OozieDBCLI.validateConnection(OozieDBCLI.java:469)
Exactly where am I supposed to copy the Mysql connector.
I have verified my oozie-site.xml-
I followed the following steps to use mysql in Oozie
My oozie directory looks like-
You have to copy mysql-connector-java-5.1.29-bin.jar to /opt/oozie_install/oozie-3.3.0-cdh4.2.2/libext directory then restart oozie instance. Make sure that mysql user oozie has suffient privileges to the database oozie, if not, grant suffient permission using grant command in mysql server.
i meet the same problem finally i solve it by edit the oozie-env.sh and append the JAVA_HOME at last export JAVA_HOME=/usr/local/jdk1.7 the java_home is yourself javapath
I ran into this issue when I was converting my local Derby instance to MySql. The difference between my issue and the others, is that I did not install an RPM. My Oozie instance was pre-compiled in a tar.gz file. I had to copy the mysql-connector-java-bin.jar to the oozie-server/lib directory. This was in addition to copying it to the lib, libext, and libtools directories. I am not sure if all of those are needed, but I do know that oozie-server/lib is needed for Oozie to start. Hope this helps someone!

Resources