I have installed Oracle 11.2 and Java:
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
In the command line, if i try to:
java oracle.jdbc.driver.OracleDriver
Java says: impossibile to load or find oracle.jdbc.driver.OracleDriver
I have copied ojdbc5.jar, ojdbc6.jar and ojdbc6_g.jar
From oraclexe\app\oracle\product\11.2.0\server\jdbc\lib to
C:\Program Files\Java\jdk1.7.0_09\lib
If i run echo %CLASSPATH% I get:
C:\Program Files\Java\jdk1.7.0_09\lib (ie where I have copied the jar files)
Any reasons why Java can't find oracle.jdbc.driver.OracleDriver ?
You reference a folder on the classpath and expect it to load all jars in it. That is not how the classpath works, you need to reference specific jars (and normally you should NOT put third party jars inside the JDK folder).
It is also important to know that the CLASSPATH is usually ignored by java applications, except for the most basic use cases.
You can do what you try to achieve by doing:
java -cp <path-to>\ojdbc7.jar oracle.jdbc.OracleDriver
This will fail btw because OracleDriver has no public static void main(String[] args) method and therefor cannot be run like this. The normal way to use a JDBC driver is to have the driver on the application classpath, and simply specify the right driver URL. JDBC 4.0 (Java 6) or higher compliant drivers will be automatically loaded from the classpath (as specified with -cp, the Class-Path manifest entry etc).
On an unrelated note, oracle.jdbc.driver.OracleDriver is considered deprecated, use oracle.jdbc.OracleDriver instead, see Difference between Oracle jdbc driver classes?
Putting a directory on the classpath doesn't put all the jar files within that directory on the classpath. It's not clear why you've copied the Oracle jar file into your Java installation directory - I'd recommend not doing that - but you should just list the location explicitly. For example, if you've copied it into the lib directory relative to your application, you could use:
java -cp lib\ojdbc7.jar;. your.class.Name
You can use * in a -cp command line argument to find all jar files, e.g.
java -cp lib\*;. your.class.Name
or you could copy it into an "extensions" directory - but I think it's clearer to be explicit.
I also had same problem and this is what i did
I extracted ojdbc5.jar and then i copied oracle folder in extracted ojdbc5.jar and then pasted in current location where i wrote jdbc program ( not mentioning the directory as it differs from programmer to programmer), then used import oracle.jdbc.*; statement in my jdbc program as oracle.jdbc has OracleDriver in it.
Rest of the program is same
Before copying ojdbc6.jar to <jdk-home>/jre/lib/ext/, in IDEA you need to add the ojdbc6.jar file in "Structure" -> "SDK" -> "add classpath" to <jdk-home>/jre/lib/ext/ojdbc6.jar
Related
I have a Mariadb database running on a Synology NAS which I want to access from Matlab installed on a Mac.
Here are the steps I have followed:
downloaded the MariaDB Connector/J 2.3.0 mariadb-java-client-2.3.0.jar
created a folder MyDrivers in the /Library folder and moved the driver there
added the above folder to the PATH variable
added the full path of the driver to the CLASSPATH variable
as per Matlab's tutorial, created a javaclasspath.txt file which is saved in the Matlab prefdir folder (/Users/cedric/Library/Application Support/MathWorks/MATLAB/R2018a/javaclasspath.txt). The content of the javaclasspath.txt file is /Library/MyDrivers/mariadb-java-client-2.3.0.jar
When I try to configure the data source in Matlab, I get an error message "Unable to find jdbc driver on Matlab Java class path". I believe points 3, 4 and 5 are properly done (cf outputs below).
So my questions are around the copy / paste of the .jar file of the driver. Is there anything I need to do on top of placing it in a relevant folder?
I've tried to execute it with java -jar /Library/MyDrivers/mariadb-java-client-2.3.0.jarin the Terminal. This provides: no main manifest attribute, in /Library/MyDrivers/mariadb-java-client-2.3.0.jar
Thinking it might not be an executable jar, I've tried java -cp /Library/MyDrivers/mariadb-java-client-2.3.0.jar org.mariadb.jdbc.Driver;
This returns
Error: Main method not found in class org.mariadb.jdbc.Driver, please define the main method as: public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application`
Any hints as to what to do exactly? I'm running out of tips from the researches I have done so far...
Output of env in the Terminal
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/48/d95l77ys4hv4xbfgtsh0rh1w0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.l8pI2zNcXw/Render
TERM_PROGRAM_VERSION=404
OLDPWD=/Users/cedric/.Trash/mariadb-java-client-2.2.6-sources 23.44.30/org/mariadb
TERM_SESSION_ID=396C6E65-006B-4BAF-B137-A270A36E397F
USER=cedric
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.QZhGI9ZjXf/Listeners
PATH=/Library/MyDrivers/mysql-connector-java-8.0.12/mysql-connector-java-8.0.12.jar:/Library/MyDrivers:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/cedric
LOGNAME=cedric
CLASSPATH=.:/Library/MyDrivers/mariadb-java-client-2.3.0.jar:
LC_CTYPE=UTF-8
SECURITYSESSIONID=186a8
_=/usr/bin/env
Output of javaclasspath('all') in Matlab
The last file that Matlab returns is the one of the driver: /Library/MyDrivers/mariadb-java-client-2.3.0.jar
System Specs:
Mac OS HighSierra 10.13.4
Matlab R2018a
Java -version:
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Driver Jdbc MariaDB Connector/J 2.3.0
Your attempts to run the mariadb jar show that it is fine. java is (correctly) telling you that this jar (nor the Driver class) can be treated as an application entrypoint.
Adding the lib to PATH does nothing.
adding the lib to CLASSPATH isn't recommended but can help; the only thing it does is define the classpath a java VM will use if no explicit classpath is provided. Matlab, like just about every complex java app, definitely has its own classpath. I'm not personally familiar with how matlab does things, but I'd give it 99% odds that matlab therefore completely ignores the CLASSPATH variable too.
That leaves this classpath.txt file which seems to be ignored. I don't think that's the way to configure classpath in matlab. The documentation over at https://www.mathworks.com/help/matlab/ref/javaclasspath.html should help you out. At the very least you can ask matlab about what it thinks the classpath is.
The hardest issue to solve is the non-existing one...
Thanks to rzwitserloot who confirmed the driver was well installed, i decided to go step by step. First set up a tiny java programme to test the driver which proved fine indeed, after adjustment of couple of database connection settings (port and ip). Then, despite the MATLAB message of driver not to be found, i did the same with matlab (coding instead of using the interface). This worked fine as well actually.
After that, I did try to connect via the database interface, despite the "unable to find driver" message. Connection succeeded, and the "unable to find driver" message disappeared.
I am just learning Java and I wanted to know that everywhere its written that JVM present inside JRE. I just wanted to know the complete path where exactly JVM is present inside JRE.
In Windows : inside your JRE, you will have a folder like this : C:\Program Files (x86)\Java\jre7\bin\client --> this directory contains the client JVM jvm.dll.
Under :linux you will find it in /jreInstallation/lib/yourSystemArchtecture(amd64 in my case)/(server/client)/libjvm.so
A VM is nothing but a shared library like dll or so file. Your java exe or other executable file calls the jvm.
Note : You can call your JVM using any language / executable file/ You could write a shell script or a cobol program to execute the JVM
Windows 10, mine:
C:\Users\elb>where java
C:\ProgramData\Oracle\Java\javapath\java.exe
c:\Program Files\Java\jdk1.7.0_07\bin\java.exe
If you intend to use the Invocation API in a native application and access Java APIs installed as part of OpenJDK (Java 10, Java 11, etc.) in ${JAVA_HOME} directory, link against (or dynamically load) jvm.dll found in ${JAVA_HOME}/bin/server/jvm.dll.
Oracle installers (currently up to Java 8) add a Windows Registry key pointing to jvm.dll. For example, when JRE 8 is installed, the following key is added:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.8
and it contains a string value RuntimeLib set to absolute path to jvm.dll. Also, information that 1.8 is the CurrentVersion can be found in key:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
As of Java 9, Oracle abbreviated Java Runtime Environment to JRE, so the keys are:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE\9
This is all documented Windows Registry Settings section of the installation guide.
is there a way, that i could load a propertie file in a QSH Command.
The Problem is my System is running on a Java 1.4 Version and my Programm is only running in a Java 1.6 Version. So i wrote a propertie files that says, take the 1.6 version but i absulutly have no plan how to implemnt it in my code..
java -cp "Test.jar:lib/*" my.package.MainClass
The name of the Properie file is Java_Version.properties
Do you have any solution ?
regards
You can specify a properties file to load with the environment variable QIBM_JAVA_PROPERTIES_FILE.
QIBM_JAVA_PROPERTIES_FILE=/path/to/myproperties.properties java -cp "Test.jar:lib/*" my.package.MainClass
In addition properties in a file named SystemDefault.properties will be automatically loaded if it exists in the user home directory.
Here are some links to additional documentation that may be useful:
Installing Java on your IBM i server
Support for multiple Java Development Kits (JDKs)
Java system properties
SystemDefault.properties
Use the environment variable JAVA_HOME On IBM i 7.1, I would specify:
JAVA_HOME='/QOpenSys/QIBM/ProdData/JavaVM/jdk60/64bit'
export JAVA_HOME
java -version
IBM Support Document N1011999 Support Java Versions by Operating System Release describes the JAVA_HOME settings for various operating system releases.
I am trying to run the jar file on linux created from windows using jdk7 .
I am using the following command to run the
java -jar jarfile.jar
its running the jar and throwing the exception as un recognised class format version. because linux is showing the java version as 1.4.2 while i have extracted the jdk1.7 in the root directory but it is still taking the java version as 1.4.2 . what i have to do to run the jar file created using jdk1.7 . I have extracted the java (jdk1.7) on linux in root directory.
You need to specify the JDK 1.7 on your path e.g.
$ PATH=/jdk17/bin:$PATH
Note how you specify not just the path to the 1.7 installation, but the bin path within that.
Typing
$ which java
after you've changed the PATH will confirm if this has worked.
Make sure jdk1.7 in front of jdk1.4.2 in system variable PATH. Do you have installed oracle in your Linux OS? I have encountered the same question in windows OS because I have installed oracle. If some software just like oracle is installed, maybe it will insert jdk1.4 in front of all other software paths in system variable PATH.
I want to upgrade my jaxws to 2.2 (jdk1.6 comes bundled with jaxws 2.1). My jdk is (I did not install public jre):
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)
In jaxws' own doc they explain how to do it:
One way to fix this is to copy jaxws-api.jar and jaxb-api.jar into JRE endorsed directory, which is $JAVA_HOME/lib/endorsed (or $JDK_HOME/jre/lib/endorsed)
But I am not sure this is having any effect in my installation. For starters I have only defined %JAVA_HOME%. And folder $JAVA_HOME/lib/endorsed is inexistant, so I created and copied the two jars. But if I do (wsgen is a tool from jaxws)
wsgen -version
I still get:
JAX-WS RI 2.1.6 in JDK 6
I also tried creating folder JAVA_HOME\jre\lib\endorsed (notice that in the doc they say JDK_HOME, but as I only have JAVA_HOME I used this path). Still same wsgen output.
My questions are:
What is the difference between JAVA_HOME and JDK_HOME in the doc page? anything significant or just two ways to refer to JAVA_HOME ?
Is 'wsgen -version' a valid way to check jaxws version that is used or this always calls the exe in the original jdk, but it does not mean endorsed jars will be used?
Anyone knows very detailed steps to install jaxws2.2 in a jdk.16?
I found this post that has some hints about what I am seeing I think
You should check you system property java.endorsed.dirs, e.g. by calling System.getProperty("java.endorsed.dirs"). On a Windows machine, this is usually something like C:\Program Files\Java\jdk1.6.0_16\jre\lib\endorsed. Put the jar files you want to endorse here. If that directory does not exist just create it.
Another option is to put the jars in a directory of your own preference, but override the system property by adding a command line switch -Djava.endorsed.dirs=<Your endorsed jars directory>.
The wsimport and wsgen included in the jre are located in the jre/bin directory as exe and if you still call it from command line, it will still run the Jax-WS 2.1 implementation.
To update to Jax-WS 2.2, you need to download the relevant JAX-WS 2.2.X RI from the jaxws website.
You need to extract the contents onto your computer.
You also need to copy the jaxws-api.jar and jaxb-api.jar into the endorsed directory (as per your original description)
HOWEVER, instead of using wsgen.exe or wsimport.exe (as applicable to your project), you now need to use the one provided in the jax-ws 2.2 update/download.
In the jaxws-ri directory that you've extracted from your JAX-WS 2.2 download, you will see a bin directory and 4 files (wsgen.bat, wsgen.sh, wsimport.bat, wsimport.sh) and these are the ones which you need to run instead.
To run them, you have to set up the JAXWS_HOME environment variable (see the wsgen/wsimport.bat/sh files for details).
That should now allow you to run JAX-WS 2.2 with JDK 1.6
It isn't tied to your environment variables. %JAVA_HOME% is just shorthand in the documentation that doesn't know where you installed Java or what version of Java you installed.
%JAVA_HOME% refers to a JRE (the regular runtime a non-developer would have). %JDK_HOME% refers to the rood directory of a JDK, a Java Development Kit, something a developer would use.
More than that, you have to know when you run wsgen where it is being run from, and that the corresponding JVM is configured with an endorsed directory that contains the jars.