How to add Oracle Database Driver in a Java Play project? - java

I'm going to access a database using OJDBC. My project is a Java play project and using SBT. I added,
"com.oracle" % "ojdbc14" % "10.2.0.4.0"
But when I'm compiling the project with this,
It says,
::::::::::::::::::::::::::::::::::::::::::::::
[warn]:: FAILED DOWNLOADS ::
[warn]:: ^ see resolution messages for details ^ ::
[warn]::::::::::::::::::::::::::::::::::::::::::::::
[warn]:: com.oracle#ojdbc14;10.2.0.4.0!ojdbc14.jar
[warn]::::::::::::::::::::::::::::::::::::::::::::::
Also I tried to download the jar manually using this link. Then I got 404.
Is there a way to add the OJDBC14 dependency to a Java play project?

For the maven users (like me) who are trying to download the jars from maven repo: Stop!
The jar's metadata is indexed and pom file is available on maven central but the actual jar is not available. Try clicking on the download link:
http://mvnrepository.com/artifact/com.oracle/classes12/10.2.0.2.0
http://mvnrepository.com/artifact/com.oracle/ojdbc14/10.2.0.4.0
So, you need to get the jar from http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
And then install to your local repo.
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 \
-Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=ojdbc.jar -DgeneratePom=true
In SBT's config add
resolvers += Resolver.mavenLocal to enable local maven repo
P.S.: If you are still reading it: I wish oracle deployed them on maven, (with a note stating if you are using the jar means you are agreeing our terms)!

You can download ojdbc.jar in the following link
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Maven repo does not offer a ojdbc jar link, because oracle Unauthorized

Oracle has a Maven repository now. https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides

Related

Missing pom errror in maven while downloading ws4j dependency

I want to use ws4j for my project. And i can't able to connect to the internet all the time. So, most of time i download dependency to local repository using dependency:get command. Then i use it in project.
like that i tried download ws4j-1.0.1. But i get a error while downloading. It says Missing POM for edu.cmu.lti:ws4j:jar:1.0.1. But there is a pom file in the repository. see the url ws4j repository. But why i get the error.
The command i used was mvn dependency:get -Dartifact=edu.cmu.lti:ws4j:1.0.1
The image of the error i get
I am using maven version 3.6.3
Please, someone help to solve this issue.
mvn dependency:get -Dartifact=edu.cmu.lti:ws4j:1.0.1
This tries to download the dependency from https://repo.maven.apache.org/maven2/ and since it does not find the dependency there, it fails.
You need to specify "-DremoteRepositories" to fetch it from a remote repository.
For example: mvn dependency:get -Dartifact=org.apache.maven:maven-core:2.2.1:jar:sources -DremoteRepositories=https://repo.maven.apache.org/maven2 -Ddest=/tmp/myfile.jar
Please refer https://maven.apache.org/plugins/maven-dependency-plugin/usage.html

Building a Maven project offline

I am trying to install OreKit (an orbital mechanics toolkit) to validate some code i've written. Orekit is a maven project and thus it tries to download all its dependencies from the maven repo.
Unfortunately my company has pretty strict internet security measures and the maven repo is not whitelisted. The only way to access non-whitelisted websites is through a secure browser (tightGate) which is basically a video-feed of the browser running on a server. Files downloaded in this browser can then be transfered to my computer using a separate program.
This of course means that the build fails. I have been trying to download all the dependencies manually and put them in the local repository.
example:
eclipse error: "Missing artifact junit:junit:jar:4.12"
I downloaded the corresponding jar and pom files (junit-4.12.jar and junit-4.12.pom) and put them into my local repository (C:/Users//.m2/repository/junit/junit/4.12/)
I did this for every error eclipse reported but nothing changes and the same errors are still there.
Am i doing something wrong here? Is it even possible to build a project this way or should i just give up already?
In principle, this could work, but it would be easier to use mvn install:install-file for the separate jars.
Be aware that the number of artifacts that Maven usually requires is > 100.
We also have strict regulations, but managed to get an extra server with a Nexus that proxies MavenCentral, so we can reach the artifacts through there.
to put jar file in your local maven repository, you must install it.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
get more info from https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Problems with an oracle maven dependency

I'm trying to compile a project in Anypoint studio, and for some reason it's failing on one dependency -
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
<version>12.1.0.2</version>
</dependency>
Should say, when I run this on my Windows laptop i have absolutely no issues and the jars download fine. Running it on my macbook, i get the following error -
Archive for required library: '/Users/matt/.m2/repository/com/oracle/jdbc/ucp/12.1.0.2/ucp-12.1.0.2.jar' in project 's-wms-hj-api' cannot be read or is not a valid ZIP file s-wms-hj-api
the message i get when i update project dependencies is -
[WARNING] Invalid POM for com.oracle.jdbc:ucp:jar:12.1.0.2, transitive dependencies (if any) will not be available, enable debug logging for more details
Is it something Mac related?
The dependency is not available in public repositories so the jar has to be installed manually in the local Maven repository. The error was likely because it was incorrectly installed.
The warning is the expected result because that method doesn't provide the pom.
I'm not sure why you don't see the warning in Windows. Perhaps a different Maven version or using a repository manager?
I've always dealt with Oracle the following way (I'm running a mac as well, though it really doesn't matter):
Download the .jar file from the internet somewhere. Install the dependency using Maven using these instructions: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Here's an example of the command, assuming you downloaded the jar for ucp version 12.1.0.2, you are currently in that directory, and the file is called ucp-12.1.0.2.jar:
mvn install:install-file \
-Dfile=ucp-12.1.0.2.jar \
-DgroupId=com.oracle.jdbc \
-DartifactId=ucp \
-Dversion=12.1.0.2 \
-Dpackaging=jar
This should install into your default ~/.m2/repository. If you want you can verify this with:
ls -al ~/.m2/repository/com/oracle/jdbc/ucp/12.1.0.2.jar
You should see a pom file in there.
Maven will now be ready to grab this file when you specify them in your pom. Keep in mind that the groupId, artifactId, and version parameters for the mvn install command relate exactly to what you'd put in the pom for those same fields.

What does it mean in Maven when it says the following artifacts could not be resolved although they are in Maven cache?

I get the following error:
The following artifacts could not be resolved: com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1: Failure to find com.sun.jdmk:jmxtools:jar:1.2.1 in https://artifactory.corp.adobe.com/artifactory/maven-identity-snapshot was cached in the local repository, resolution will not be reattempted until the update interval of artifactory-snapshot
However, both jars are in the Maven cache (.m2 folder) on my machine. I mean files named: jmxri-1.2.1.jar and jmxtools-1.2.1.jar. They are respectively in the folders com/sun/jmdk/jmxtools/1.2.1/ and com/sun/jmx/jmxri/1.2.1
EDIT: When I try the -o switch on Maven to force it to use the local jars, it says the artifact has not been downloaded before. Which is probably true since indeed the artifact is not in the repo but was copied from some other place to my Maven cache -- is it possible to force Maven to use the jars? The -o switch does not seem to force this and Maven seems to be able to detect that the artifact was not downloaded.
Try to delete corresponding artifact folders in maven local repo and rerun or just rerun using -U flag.
Which is probably true since indeed the artifact is not in the repo but was copied from some other place to my Maven cache
Manually copying jars is not the correct way to put artifacts into maven local repo. You should use mvn install:install-file instead. More details here: Guide to installing 3rd party JARs
The dependency on those jars is usually a consequence of a bug in the pom.xml for log4j 1.2.15.
Update to 1.2.16 or 1.2.17 and you will not need these jars any longer.
These particular artefacts date back to a time when Sun licensing did not permit the hosting of the actual jars in a public maven repository.
You were required to accept licence conditions, download them yourself and then manually install either into your local repo (using mvn install:install-file) or into your corporate repository manager (typically using a UI that it provides or mvn deploy:deploy-file).

Maven: How to include jars in Eclipse, which are not available in repository?

I have copied the JARs into src\main\webapp\WEB-INF\lib.
I use eclipse. If I add the jars one-by-one to Project-> Java Build Path-> Add jars, then I do Project-> Maven-> Update Project Configuration, they are removed by Maven. And Eclipse shows errors, which contain " xxx cannot be resolved".
Env:
Eclipse Java EE IDE for Web Developers.
Version: Indigo Service Release 1
Build id: 20110916-0149
m2e - Maven Integration for Eclipse 1.0.100.20110804-1717
Note: I don't want to create my own Maven repository. It will be just used once.
How should I proceed ?
Not all libraries can be found in a public Maven repository, for example your own libraries or proprietary libraries. Anyway first you can search the Maven Repository, maybe some of them are there.
In case they are really not there, and you don't want to install Nexus or Artifactory, you can choose one of these two approaches:
install the jars in your local repository cache, no need to create a special repository. See the instructions on mkyong.
another approach is using system dependencies, you just put a path to reach the Jar in the filesystem. It's a less recommended approach, but if you really want it will work. Here is the official documentation.
Add this an a Systems Dependency.
In case you want to add this (this uses jquantlib as example) to the maven local repo use:
mvn install:install-file -Dfile=./jquantlib-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib -Dversion=0.2.4 -Dpackaging=jar
In order to do this I use a batch file
#echo off
cd lib
CMD /C "mvn install:install-file -Dfile=./jquantlib-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-helpers-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-helpers -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-samples-0.2.4-ubber.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-ubber -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-samples-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-samples -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./ta-lib-0.4.0.jar -DgroupId=com.tictactec -DartifactId=ta-lib -Dversion=0.4.0 -Dpackaging=jar"
You can use a similar script file on other systems.
I believe the system dependency approach shouldn't be used unless you don't have any other choice, and that's because you're loosing the whole 'build portability thing' here.
Of course you can store your jars in your source control system together with your project's source files, but I don't think its a good approach neither...
Using only install:install-file is not good enough - this would indeed deploy the jars in the proper format into your local repository, but what happens when you'll move to another computer and start to build your project there?
You will need to make this once more.
So, If you don't want to install nexus/artifactory (which is the best solution, I believe), you probably should create an another repository (just in a file system on some of your servers), and deploy the jars there (you can use mvn install:install-file as was suggested here, and then just copy the whole tree). Now you can configure apache web server and access the directory with all your jars via http. I don't believe its better then nexus/artifactory approach, but it can be a little be easier to do if you're familiar with apache web server.
In order to get your maven aware about this new repository you'll need to edit the %MAVEN_HOME%\conf\settings.xml file
There are atleast three approaches in which 3rd party JARs can be added to Maven projects.
Install manually using mvn install command
Adding the location of jar file in pom dependency with the the following tag system
Creating a 'dummy' maven repository pointing to jar location.
While approach 1 and 2 has been suggested above, I will focus on third approach which I find more cleaner and does not require any mvn command and works out of box from any IDE.
Step 1: Add the location of local 'dummy' repository in pom.xml
<repositories>
<repository>
<id>repo</id>
<name>repo</name>
<url>file:${project.basedir}/src/main/resources/lib</url>
</repository>
</repositories>
Here the 'dummy' repository location is the 'lib' folder of my project directory
Step 2 : Add the jar dependency into your pom.xml
<dependency>
<groupId>com.cloudera.impala</groupId>
<artifactId>impala-frontend</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
choose any groupId but make sure that artifactId and version is of the format <artifactId>-<version>.jar ( Name of 3rd party jar)
Step 3 : Create the folder structure as per the groupId,artifactId and version mentioned in the Step 2 in your local 'dummy' repository. So in this case the folder struction would be /src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/
Place your jar in the version folder and build your project.
You will get the following output which treats your 'dummy' repository to be the provider of your 3rd party jar.
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.pom
[WARNING] The POM for com.cloudera.impala:impala-frontend:jar:0.1-SNAPSHOT is missing, no dependency information available
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[WARNING] Could not validate integrity of download from file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar: Checksum validation failed, no checksums available
[WARNING] Checksum validation failed, no checksums available from repo for file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[INFO] Downloaded from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar (7.0 MB at 79 MB/s)
[INFO]
To add external JAR files not in the local repository simply right click on your main source folder and from the build path menu select: "configure build path", then navigate to the libraries tab and click "add external JAR files". next, locate the JAR (or zip) file you would like to add as a library and click ok.
Congratulations, you have now successfully added an external JAR (or zip) to your build path and you can now import any classes from that JAR file in your project without throwing an errorPicture How-To :) http://hostthenpost.org/uploads/541be8420657320c74489ff8d456ad08.png

Categories