简体   繁体   中英

Adding ojdbc to maven project

I'm creating a custom document library action in Alfresco Content Services 6.1.1 using alfresco-amp-archetype. I'd like to access data from external Oracle database.

I'm using ojdbc library from: https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc8/12.2.0.1

Since maven is unable to download the dependency on its own, I'm putting the jar in my project and adding it in pom (I've also added it in tomcat/lib directory):

<dependency>
     <groupId>com.oracle.jdbc</groupId>
     <artifactId>ojdbc</artifactId>
     <version>8</version>
     <scope>system</scope>
     <systemPath>${project.basedir}/src/main/resources/ojdbc8-12.2.0.1.jar</systemPath>
</dependency>

When I call the action I'm getting "java.sql.SQLException: No suitable driver found for jdbc:oracle:thin"

How should I add the driver to my project for it to work?

The system scope that you are using is more meant to include things provided by java itself and is a deprecated feature.

The jar is not in the usual maven repositories due to license restrictions. So it needs to be somewhere with private access.

If you are not running a maven repository proxy like sonatype nexus or jfrog artifactory I would recommend that you copy the jar into your own maven repository: maven deploy into local repository (probably best in a little script to repeat or share).

Don't store it in src/main/resources - everything in there will be added into the artifact you create. Choose another folder (like "dependencies" beside src) and then once copied into your local maven repository use that jar as normal dependency (remove scope and systemPath). The default scope is compile, so the jar will be included in your classpath so the driver should then be available (I assume you create some sort of war file?).

So there is also no need to manually add it into tomcat directly - but have it brought in via the war file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM