well, there are so many threads discussed about this topic , but unfortunately nothing worked for me .
I am sending username/pwd to the server and server is interacting with JDBC client . this is my goal .
but I am getting above mentioned error while executing the below piece of code
ERROR: Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
CLASSPATH varaible here :
C:\ProgramFiles\Java\jdk1.7.0_17\bin;C:\ProgramFiles\Java\jdk1.7.0_17\db\lib;C:\ProgramFiles\Java\jdk1.7.0_17\db\lib\derbyclient.jar;
I'm pretty sure this jar contains ClientDriver.class .
I dont know where I did mistake .. anyone pls help me .
The CLASSPATH environment variable is almost never used. Make sure the 'derbyclient.jar' is on the actual classpath of your application.
If running from the IDE: make sure it is on the IDE build path of your application
If running with java -jar ... make sure it is in the Class-path attribute of the META-INF/MANIFEST.MF
If running with java -cp ... make sure it is in the -cp list.
Also if you are using a JDBC 4 compliant driver, you don't need to call Class.forName("org.apache.derby.jdbc.ClientDriver"), calling newInstance() is never necessary to load the driver (unless you are using Java 1.0 or 1.1 which you aren't).
You must add derbyclient.jar to YourProject\WebContent\WEB-INF\lib. Not needed to add derby.jar to classpath.
It's helped me.
Related
I am using IntelliJ Idea 2017.3 and on any Gradle project (even for simple 'hello world' from GitHub) I always got next error:
"Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/3.5-rc-2/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error: Could not find or load main class 1.8"
Meanwhile, if I run an application with Gradle wrapper (gradlew.bat in my case) everything works perfectly. For me it looks like misconfiguration issue, but I cannot find what I am doing wrongly in Idea configuration or any other place. I appreciate any help with it or clue where to dig.
The issue was resolved and I would like to share this knowledge with all those who encounter a similar problem.
In my case, I had to delete two configuration files gradle.experimental.xml and gradle.settings.xml from IDEA configuration directory %IDEA_HOME%\config\options. I suppose they were created at the time when I installed Gradle globally on my PC. Somehow these settings were persisted, even after I removed globally installed Gradle and started to use Gradle's wrapper.
We have a Spring Boot application which is built as an executable jar and runs fine using both the Oracle and OpenJDK JREs (using 1.8 versions).
Attempting to run it using the IBM 1.8 JRE however results in the following error at the command line.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This occurs if we execute the jar (using ./application.jar) or using java -jar application.jar
This led us to change the packaging to not make the jar executable and this allows us to start the application using java -jar application.jar. So it appears the IBM JRE doesn't like the launch script.
The problem is we don't want to have two packaging methods for different deployment environments, if possible.
Does anyone have any experience of why the IBM JRE doesn't like the script on the front of the jar file and whether there are any command line options to disable whatever checking its doing?
From your post it is unclear if you have problem with
1) running jar from Linux like chmod a+x application.jar and executing
Or
2) running via /opt/IBM/java/jre/bin/java -jar application.jar
For option 1) it is not a good idea as you do not explicitly choose jvm binary and rely on OS to choose one for you.
Read about binfmt_misc mechanism:
https://en.m.wikipedia.org/wiki/Binfmt_misc
For option 2)-it might be class loading problem, please add
/opt/IBM/java/jre/bin/java -verbose:class -jar application.jar
and consult documentation here: https://www.ibm.com/developerworks/library/j-dclp1/index.html
i wanted to practice developing database programs in java so i set the classpath to E:\software\installed\java\jre\lib by declaring a new environmental variable classpath and gave value as E:\software\installed\java\jre\lib but now i am unable to run any program(not even non-database) i get an error
Error: Could not find or load main class MysqlConnect
but when i delete the classpath variable i am able to run non-database programs. what is the possible problem and please let me know the solution. i have set path to E:\software\installed\java\bin
nothing is helping i tried using class path switch in java which is not helping (java -cp C:\Program Files\MySQL\MySQL Server 5.5 MysqlConnect) nor do setting path is helping (set CLASSPATH=%CLASSPATH%:C:\Program Files\MySQL\MySQL Server 5.5:C:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar) all are giving the error
Error: Could not find or load main class MysqlConnect
You shouldn't be defining a classpath for your programs using system variables. Standard way is to use the command line -cp or -classpath option. Take a look at what java prints out if you run it with no arguments.
You will find this mentioned in this tutorial. It says:
The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications. Setting the CLASSPATH can be tricky and should be performed with care
Also, see how the default CLASSPATH environmetn variable has a . in it. If you still decide to add your classes in there, keep the . for other citizens and add your classes after a ;, don't just overwrite the whole value.
Here's a jdbc tutorial for beginners that could help you find your answer. If you skip to step 14 it gives an example of how the classpath is used. It is used as the first respondent is saying, by command line.
Hopefully this will help you in your particular situation. This tutorial is not database-specific so it will work with any type of database you are using.
ok atlast i got the solution it should be typed as
C:\Users\sarad mohanan\Desktop\rose>java -cp .;"c:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar" MysqlConnect
MySQL Connect Example.
Connected to the database
Disconnected from database
we have to add .; before the original path . holds default classpath. pravel veller had said it previously but i didn't understand it then
I would like to propose using a good tool like Eclipse. You can test the CLASSPATH indirectly and your environment by adding or removing jar files and libraries.
Obviously, the libraries in your default CLASSPATH is different than the one in your E drive. You may compare the files by knowing your CLASSPATH. In Windows, do "echo %CLASSPATH%".
Eclipse can help you by experimenting without rebooting or any annoying steps. And this stuff is not easy.
Crete o set environment variable if you use windows JAVA_HOME=E:\software\installed\java, and after append the Java bin directory %JAVA_HOME%\bin. Note that paths are separated from each other with semicolons (;) I hope help you. That's work for me !!!. I don't understand. What happen?.
I also need to generate outside eclipse and i didn't figured out how to do it.
I've read this thread but I have another problem to overcome first : I'm unable to start the main !
I tried different ways : export the project as standalone, put the project in a regular or executable jar, and launch directly Generator.class. I would like some help with the last solution. Here's how I launch it :
java -cp "..\testGene\bin\;C:\Program Files\Eclipse\plugins" testGene.main.Generate testModel.uml outputDir
I can't copy the whole console (dev computers are not connected to internet), but it says :
Exception in thread "main" java.lang.NoClassDefFoundError: org/Eclipse/acceleo/engine/service/AbstractAcceleoGenerator
Could not find the main class: testGene.main.Generate.
The generator works well inside eclipse, and I manage to call a simple test class with the same command line. I tried to copy the whole acceleo plugins in my bin directory in case the space in "Program Files" is a problem.
I'm pretty sure this is a simple error I made, any ideas ?
Furthermore, I'm not sure that it's sufficient to use the plugins folder in your classpath. Shouldn't there be a list of the jar files you need?
Since the program does not seem to find the AbstractAcceleoGenerator I would say that you are lacking some dependencies of the generator. Have a look at this screenshot to see the jar used for an UML to Java generator.
I have installed a third party java webservice which uses Oralce jdbc thin driver to write data into Oracle database. When i run this, i get the following error;
JDBC Driver class not found: oracle.jdbc.OracleDriver
I have oracle installed and set classpath variable to following value:
*D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip;C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar*
and path variable to following value;
*D:\oracle\product\10.2.0\client_1\bin;C:\Program Files\Java\jdk1.7.0\bin\;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip*
Any suggestion why web service is not able to identify jdbc driver?
Thanks
I know 2 ways of turning Java app into Windows service and both do not use CLASSPATH. One is Java Service Wrapper by Tanuki Software. This tool uses wrapper.conf where you can show directories with .jar libraries:
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=c:\jars\*
wrapper.java.classpath.2=myservice.jar
Second tool I know is JSL: Java Service Launcher. In this tool there is jsl.ini where you put command line to run your server. It can use java with -cp option to show location of .jar libraries:
[defines]
MY_LIBS=d:\jars\*
AXIS_LIBS=d:\axis2-1.5.4\lib\*
CLASSPATH=.;%MY_LIBS%;%AXIS_LIBS%
export = CLASSPATH
...
[java]
...
cmdline = -Dfile.encoding=utf8 -cp %CLASSPATH% example.my.server
In both configuration you can use * to add all .jar files or you can show those files one by one (just like in CLASSPATH).
At first you should know what Windows is trying to execute. Check it in the service properties page. Then try to localize its configuration. If it uses one of tools I know then you know what to change. Other tools probably have similar configuration.
Method 1:
Download ojdbc.jar
add ojdbc6.jar to deployment assembly.
Right click on project->properties->select deployment assembly->click on 'Add'
->select 'Archives from File System'->browse to the folder where ojdbc6.jar is saved.->add the jar->click finish->Apply/OK.
Method 2:
if you want to add ojdbc.jar to your maven dependencies you follow this link:
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/
.
.
Even if you're using a maven project it is not necessary to add ojdbc to maven dependencies(method 2), method 1 (adding directly to deployment assembly) works just fine.
Make sure you have the ojdbc jar file (make sure you are using the correct one because depending on java version you may need to choose a different one).
use ojdbc14.jar for Java 1.4
use ojdbc5.jar for Java 1.5
ojdbc6.jar for Java 1.6
here is linke where you can download ojdbc6.jar file
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
You also have to add the jdbc jar to your server classpath. if tomcat, rigth-click on your Project->run as->run configurations, click on classpath and add your jdbc jar in Add external jars option
add ojdbc-6.jar to your lib directory of tomcat installation. Maven will downlowd this jar for you in .m2 directory, but you need to have this jar in tomcat lib as well.