I want to add the oracle jdbc driver to my project as dependency (runtime scope) - ojdbc14.
In MVNrepository site the dependency to put in the POM is:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
of course this does't work as it is not in the central repository used by maven.
2 questions:
How do I find a repository (if any) that contains this artifact?
How do I add it so that Maven will use it?
How do I find a repository (if any) that contains this artifact?
Unfortunately due the binary license there is no public repository with the Oracle Driver JAR. This happens with many dependencies but is not Maven's fault. If you happen to find a public repository containing the JAR you can be sure that is illegal.
How do I add it so that Maven will use it?
Some JARs that can't be added due to license reasons have a pom entry in the Maven Central repo. Just check it out, it contains the vendor's preferred Maven info:
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
...and the URL to download the file which in this case is
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html.
Once you've downloaded the JAR just add it to your computer repository with (note I pulled the groupId, artifactId and version from the POM):
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 \
-Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar -DgeneratePom=true
The last parameter for generating a POM will save you from pom.xml warnings
If your team has a local Maven repository this guide might be helpful to upload the JAR there.
The Oracle JDBC Driver is now available in the Oracle Maven Repository (not in Central).
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
The Oracle Maven Repository requires a user registration. Instructions can be found in:
https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides
Update 2019-10-03
I noticed Spring Boot is now using the Oracle JDBC Driver from Maven Central.
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.3.0.0</version>
</dependency>
For Gradle users, use:
implementation 'com.oracle.ojdbc:ojdbc10:19.3.0.0'
There is no need for user registration.
Update 2020-03-02
Oracle is now publishing the drivers under the com.oracle.database group id. See Anthony Accioly answer for more information. Thanks Anthony.
Oracle JDBC Driver compatible with JDK6, JDK7, and JDK8
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
Oracle JDBC Driver compatible with JDK8, JDK9, and JDK11
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
Oracle JDBC Driver compatible with JDK10 and JDK11
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.3.0.0</version>
</dependency>
For whatever reason, I could not get any of the above solutions to work. (Still can't.)
What I did instead was to include the jar in my project (blech) and then create a "system" dependency for it that indicates the path to the jar. It's probably not the RIGHT way to do it, but it does work. And it eliminates the need for the other developers on the team (or the guy setting up the build server) to put the jar in their local repositories.
UPDATE: This solution works for me when I run Hibernate Tools. It does NOT appear to work for building the WAR file, however. It doesn't include the ojdbc6.jar file in the target WAR file.
1) Create a directory called "lib" in the root of your project.
2) Copy the ojdbc6.jar file there (whatever the jar is called.)
3) Create a dependency that looks something like this:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>14</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath> <!-- must match file name -->
</dependency>
Ugly, but works for me.
To include the files in the war file add the following to your pom
<build>
<finalName>MyAppName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/java</directory>
<targetPath>WEB-INF/classes</targetPath>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.css</include>
<include>**/*.html</include>
</includes>
</resource>
<resource>
<directory>${basedir}/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Download the jar and place it in your project src/lib. Now you can use the maven installer plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install-oracle-jdbc</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>clean</phase>
<configuration>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<createChecksum>true</createChecksum>
<file>${project.basedir}/src/lib/ojdbc6.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Now you only have to execute mvn clean once and the oracle lib is installed in your local maven repository.
Oracle is now exposing a maven repository at maven.oracle.com
However you need to be authenticated.
See https://blogs.oracle.com/WebLogicServer/entry/weblogic_server_and_the_oracle
According to the comments in the blog post the ojdbc driver should be available at the following coordinates:
<groupId>com.oracle.weblogic</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.3-0-0</version>
<packaging>jar</packaging>
Try with:
<repositories>
<!-- Repository for ORACLE ojdbc6. -->
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
</dependencies>
1. How do I find a repository (if any) that contains this artifact?
As DavidS has commented the line I quoted at the time I answered is no longer present in the current (at the time I'm writing now) OTN License Agreement agreement I linked. Consider this answer only for older version of the artifact, as the 10.2.0.3.0 and the like.
All Oracle Database JDBC Drivers are distribuited under the OTN License Agreement.
If you read the OTN License Agreement you find this license term:
You may not:
...
- distribute the programs unless accompanied with your applications;
...
so that's why you can't find the driver's jar in any public Maven Repository, because it would be distributed alone, and if it happened it would be a license violation.
Adding the dependency:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
(or any later version) make Maven downloads the ojdbc14-10.2.0.3.0.pom only, and in that pom you can read:
...
<licenses>
<license>
<name>Oracle Technology Network Development and Distribution License Terms</name>
<url>http://www.oracle.com/technology/software/htdocs/distlic.html</url>
</license>
</licenses>
...
which informs you about the OTN License.
2. How do I add it so that Maven will use it?
In order to make the above dependency works I agree with victor hugo who were suggesting you here to manually install the jar into your local Maven repository (the .m2 directory) by running:
mvn install:install-file -Dfile={Path_to_your_ojdbc.jar} -DgroupId=com.oracle
-DartifactId=ojdbc -Dversion=10.2.0.3.0 -Dpackaging=jar
but I want to add that the license term above doesn't limit only where you can't find the JDBC jar, but it limits where you install it too!
In fact your local Maven repository must be private and not shared because if it was shared it would be a kind of distribution in which the jar is distributed alone, even if to a little group of people into your local area network, and this represent a OTN License Agreement violation.
Moreover I think you should avoid installing the JDBC jar in your corporation repository manager (such as Artifactory or Nexus) as a single artifact because if it was installed it would be still distributed alone, even if to people in your organization only, and this represents a OTN License Agreement violation.
You can use Nexus to manage 3rd party dependencies as well as dependencies in standard maven repositories.
As of today (27, February 2020) Oracle announced that it has published all JDBC client libraries from version 11.2.0.4 (e.g. ojdbc6) to 19.3.0 (e.g. ojdbc10) on Maven Central under the group id com.oracle.database:
Example:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.3.0.0</version>
</dependency>
Up to now, its not possible to use maven repositories. I'm using ivy as dependency management tool, but also use maven2' s ibiblio repositories. And this is working for ivy:
<dependency org="oracle" name="ojdbc14" rev="10.2.0.2" conf="*->default"/>
Maven2' s dependency could be something like that:
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2</version>
</dependency>
Notice that i define http://download.java.net/maven/2/ and http://mirrors.ibiblio.org/pub/mirrors/maven/mule/dependencies/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext] as external maven2 repos on my ivy settings.
The Oracle JDBC drivers are now available in Maven Central.
Here is the Link:
Oracle JDBC Drivers - Maven Central
Oracle developers article announcing the availability of the Oracle JDBC drivers in Maven Central:
Oracle announcing - Oracle JDBC drivers available in Maven Central
Example:
<!-- https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc10 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.3.0.0</version>
</dependency>
Good news everyone! Finally we can use Oracle's official repo:
https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides
In my case it works for me after adding this below version dependency(10.2.0.4). After adding this version 10.2.0.3.0 it doesn't work due to .jar file not avail in repository path.
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4</version>
I ship opensource under LGPLv2 and even after several email conversations with Oracle they were unclear whether I was allowed to ship their binary JDBC driver with my distribution. The issue related to whether my license was compatible with their OTN terms so they suggested I was not permitted to ship the driver. Presumably related to this part
(b) to distribute the programs with applications you have developed to your customers provided that each such licensee agrees to license terms consistent with the terms of this Agreement
So even if you manage to publish the driver legally in your exclusive/local maven repository there is still the restriction on what you are permitted to do with that artifact. Seems absurd that even if I ship their driver in binary form along with the full OTN license file I still can't use it and must force my users to manually download the Oracle driver and drop into my library path before they can use my software.
There is one repo that provides the jar. In SBT add a resolver similar to this:
"oracle driver repo" at "http://dist.codehaus.org/mule/dependencies/maven2"
and a dependency:
"oracle" % "ojdbc14" % "10.2.0.2"
You can do the same with maven. pom.xml and jar are available (http://dist.codehaus.org/mule/dependencies/maven2/oracle/ojdbc14/10.2.0.2/).
If you are using Netbeans, goto Dependencies and manually install artifact. Locate your downloaded .jar file and its done. clean build will solve any issues.
Please try below:
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
This worked for me like charm. I went through multiple ways but then this helped me.
Make sure you follow each step and name the XML files exactly same.
https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides
The process is a little tedious but yes it does work.
You can find a Github simple sample project for use a Oracle JDBC Driver on Maven Project here.
You can find all explication for your continous integration + a sample and run on Travis-CI.
DEMO
pom.xml
<properties>
<oracle.driver.version>12.2.0.1</oracle.driver.version>
</properties>
<repositories>
<repository>
<id>maven.oracle.com</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.oracle.com</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<url>https://maven.oracle.com</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>${oracle.driver.version}</version>
</dependency>
</dependencies>
mvnsettings.xml
<settings>
<servers>
<server>
<id>maven.oracle.com</id>
<username>${OTN_USERNAME}</username>
<password>${OTN_PASSWORD}</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>
</settings>
How to use on local environment
change ${OTN_USERNAME} by your Oracle login in test/mvnsettings.xml file
change ${OTN_PASSWORD} by your Oracle password in test/mvnsettings.xml file
mvn clean install --settings test/mvnsettings.xml
For dependency
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
Try
<repository>
<id>mvnrepository</id>
<url>http://nexus.saas.hand-china.com/content/repositories/rdc</url>
</repository>
SOLVED
Please do following settings to resolve the error
This repository needs to be enable for finding Oracle 10.0.3.0 dependecies (this setting needs to be done in Buildconfig.groovy
grails.project.dependency.resolver = "ivy" // or ivy
Also use following setting for compile time Oracle driver download
runtime "com.oracle:ojdbc:10.2.0.3.0"
This should solve your issue for not finding the Oracle driver for grails application
Related
I will be quick. My maven version is 3.5.0. I'm using some libraries in my web applications. The libraries are installed separately and deployed in an artifactory instance.
I have the following pom (part of):
<project>
....
<properties>
<process.domain.common.version>0.0.1-SNAPSHOT</process.domain.common.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.intersoft</groupId>
<artifactId>process.domain.common</artifactId>
<version>${process.domain.common.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.intersoft</groupId>
<artifactId>process.domain.common</artifactId>
</dependency>
</dependencies>
</project>
but in the libs, Maven puts this library:
process.domain.common-0.0.1-20190319.151024-3.jar
instead of this:
process.domain.common-0.0.1-SNAPSHOT.jar
My dependencies are resolved from artifactory. Why does Maven put this temporary library with timestamp name instead of the SNAPSHOT? This behavior does not happen in all resolved libraries.
Finally, i found the solution.
The solution is to add maven war plugin in your pom.xml of the war project:
<properties>
<version.war.plugin>2.5</version.war.plugin>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
Proof:
WEB-INF/lib without the war plugin:
WEB-INF/lib with the war plugin:
Maven append the current date to snapshots for compare the snapshot version from your local repository and the snapshot version from remote repository and evaluate if is required download remoting jar, because that downloading 0.0.1-SNAPSHOT today might give a different file than downloading it yesterday or tomorrow.
If you build a Snapshot locally, it is just build with the name 0.0.1-SNAPSHOT. If you deploy it to Artifactory, it gets an internal timestamp version number like the one you mentioned.
When you download it again, Artifactory gives you the latest timestamp.
So locally, you sometimes have a -SNAPSHOT version and sometimes a timestamp version. The exact rule how the artifact in the war is named is unclear to me, but whether you have timestamped version or not, you should be fine.
I am trying to access DB2 tables in a java project. I am able to access the tables when I manually added the jar files - db2jcc4.jar and db2jcc_license_cisuz.jar. No issues in accessing the tables.
But when I try to add these jar files through Maven, they won't add to the project.
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc4</artifactId>
<version>9.7.0.4</version>
</dependency>
Error Message - Missing artifact id.
Also, the latest db2jcc4.jar files (Version 11.1) are not present in Maven repository. Is there any other place I can access it from?
You have to download the right driver from IBM.
http://www-01.ibm.com/support/docview.wss?uid=swg21363866
Then install it to your local maven repository
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html
As written in maven central repository the artifact is in another repo.
Add it to your pom and it will work.
<repositories>
<repository>
<id>Alfresco</id>
<name>Alfresco</name>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
</repository>
</repositories>
Assuming that , using share drive is the option to go.
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>licences</artifactId>
<version>0.7</version> <!-- Adjust this properly -->
<scope>system</scope>
<systemPath>R:\JDBC drivers\IBM DB2_db2_2.2.0.v20130525_0720\db2jcc_license_cisuz.jar</systemPath>
</dependency>
According to maven central repository the artifact is in another repository. Include these two in your pom.xml and it should work:
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
</dependency>
<repositories>
<repository>
<id>com.ibm.db2.jcc</id>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
</repository>
</repositories>
I need to work with be.ac.ulg.montefiore.run.jahmm package for Hidden Markov Models in java.
My project is a mevenized project so I need to use the corresponding dependency.
<dependency>
<groupId>be.ac.ulg.montefiore.run.jahmm</groupId>
<artifactId>jahmm</artifactId>
<version>0.6.2</version>
</dependency>
The above dependency is not being resolved in my project.
Does anyone know how to help me?
Thank you.
Your dependency is not in the Maven Central Repository.
Find out the repository used by the authors to publish their artifacts and add this repository to your POM or to your settings.xml.
If it is not published to the usual online maven repositories, you will need to install it on your local machine first.
So download the sources, go to the top level and do the usual
mvn install
Once you installed jahmm locally, your project can resolve it from your maven cache.
Adding this repository should do the trick:
<repositories>
<repository>
<id>jsi</id>
<url>http://repo.springsource.org/libs-release-remote</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>be.ac.ulg.montefiore.run.jahmm</groupId>
<artifactId>jahmm</artifactId>
<version>0.6.2</version>
</dependency>
...
</dependencies>
I am using a project's open source that consists of a set a parent POM and
several children POM. Those children POM represent libraries, arch-types and
a plug-in. This plugin depends on various of these children modules and is
used within the section of dependent projects like mine.I have imported
this Maven project to my Eclipse workspace.
In my own project's POM (also in Eclipse) I can reference those modules via
dependencies without a problem. However I would also like to use the plug-in in
the build section but it cannot be used due to the following Maven2 error:
Project build error: Unresolveable build extension: Plugin org.grouplens.lenskit:lenskit-eval-maven-plugin:2.1-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact org.grouplens.lenskit:lenskit-eval-maven-plugin:jar:2.1-SNAPSHOT
This is because I am accessing the POM's directly via Eclipse's "resolve dependencies
from workspace projects" and of course this snapshot version has not been deployed to
a repository so this is the only way I can actually use it.
I tried:
Add any of the dependencies of lenskit-eval-maven-plugin:
Their are several but I just added the only one of the project's
module (others include stuff like maven-plugin-api):
<dependency>
<groupId>org.grouplens.lenskit</groupId>
<artifactId>lenskit-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
placing a dependency for that plugin module before using the module in the section
<dependency>
<groupId>org.grouplens.lenskit</groupId>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<version>${lenskit.version}</version>
</dependency>
adding a dependencies in the plug-in itself so:
<build>
<plugins>
<plugin>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<groupId>org.grouplens.lenskit</groupId>
<!-- TODO -->
<version>${lenskit.version}</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>org.grouplens.lenskit</groupId>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<version>${lenskit.version}</version>
</dependency>
</dependencies>
And using (0), (1) and (2) at the same time
Ok, so I realize that attempt (2) is pushing it. So my question is: is their
any way I can use a plug-in in the build section that is also a dependency?
If so how? If the use of solution (1) is correct, could this be an issue with
Eclipse's method of resolving to local workspace first?
TIA
There is no existing artifact for maven2 from its default repo. Try adding explicit repo or this plugin is not suitable for maven2 (check this for maven3, I dont have any problems).
In maven central you will not find any snapshot version of such things only release. In your case you need to use a different version of the plugin like this:
<groupId>org.grouplens.lenskit</groupId>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<version>2.0.2</version>
which is of Sep. 2013...
The thing which you mentioned in your question like this:
<build>
<plugins>
<plugin>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<groupId>org.grouplens.lenskit</groupId>
<!-- TODO -->
<version>${lenskit.version}</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>org.grouplens.lenskit</groupId>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<version>${lenskit.version}</version>
</dependency>
</dependencies
does not make sense, cause you define a plugin where you like to add the same plugin onto the classpath of the plugin.
The only thing which will bring you to solve the problem is using the right version like this:
<build>
<plugins>
<plugin>
<artifactId>lenskit-eval-maven-plugin</artifactId>
<groupId>org.grouplens.lenskit</groupId>
<!-- TODO -->
<version>2.0.2</version>
<extensions>true</extensions>
<...>
</plugin>
...
</plugins>
</build>
You might need to add a <pluginRepository> in your settings.xml or in POM for your snapshot version of the plugin, because plugins are not being searched in normal repositories.
UPDATE
Your local maven repo is an auto-created cached version of online repos under $HOME/.m2/repository.
-SNAPSHOT versions which are deployed to Central repo are usually stored on some other address, which must be explicitly set. Adding this should help to use the snapshot version if you don't have this in your POM/settings.xml:
<pluginRepositories>
<pluginRepository>
<id>sonatype-snapshots</id>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</pluginRepository>
</pluginRepositories>
I hope I'm explaining this as accurately as possible, and I want to know if I set up the maven dependencies correctly, or if there's a better way to do it.
Most of my development team's projects rely on a home-grown jar that is deployed at server class loader. The reason for this jar to reside at this level is to the ease of updating the jar at one place without repackaging each project that's using it, assuming changes made to it are backward-compatible.
I develop my web apps against Jetty in my local development. So, in order for the web apps to work locally, I set up the dependencies this way:-
<dependencies>
<!-- Configuring external jar dependency -->
<dependency>
<groupId>com.test.app</groupId>
<artifactId>app-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${env.EXTERNAL_JAR}</systemPath>
</dependency>
...
</dependencies>
<build>
<plugins>
<!-- Configuring Jetty -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<contextPath>/${project.parent.artifactId}</contextPath>
<jettyEnvXml>${env.JETTY_ENV_XML}</jettyEnvXml>
<scanIntervalSeconds>1</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>7777</port>
</connector>
</connectors>
<webAppConfig>
<extraClasspath>${env.EXTERNAL_JAR}</extraClasspath>
</webAppConfig>
</configuration>
</plugin>
...
</plugins>
</build>
In this approach, I set up an environment variable that points to the external jar path, and reference it in my pom.xml as ${env.EXTERNAL_JAR}.
After doing some reading, it seems like using "system" scope is considered a bad practice. So, I installed this external jar in Nexus and change the scope to "provided":-
<dependency>
<groupId>com.test.app</groupId>
<artifactId>app-jar</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
This allows me to compile my project properly, but I'm not sure if it is even possible for me to get rid of the "EXTERNAL_JAR" environment variable completely because it's still needed by Jetty for the runtime to work properly. My take is using "provided" scope is a little tedious and more work, because I now need to remember to update the jar in Nexus when it is modified AND I still need to update the jar located at the path pointed by the environment variable.
Is there a way for me to expose the external jar to Jetty through maven dependencies, yet not being packaged into the project when the war file is built?
What are you advice on this? Should I just stick with "system" scope so that I just need to update the jar at one place, or should I use "provided" scope? Or if there's even a better way to do this?
Thanks much.
You should be able to add dependencies to the jetty plugin. And then I have the provided scope for the project itself.
http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
as in
<project>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<name>logback.configurationFile</name>
<value>./src/etc/logback.xml</value>
</systemProperty>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.15</version>
</dependency>
</dependencies>
</plugin>
...
<project>
The best thing to do is setup an external repository with your dependency, and add it to your pom.
<repositories>
<repository>
<id>my-repo</id>
<name>my-repo</name>
<url>http://your.repo.url</url>
</repository>
</repositories>
and then you can add your dependency as
<dependency>
<groupId>com.test.app</groupId>
<artifactId>app-jar</artifactId>
<version>1.0</version>
</dependency>
I approve of provided. Provided means - download the dependency for compile-time, but I expect to see it on classpath on the application server.
I did not realize you care only for your local development, so the following would be useful if you were running Jetty on an external server:
Maven will let you deploy a file to a server using the Wagon plugin. So a part of your build process could be pushing the proper .jar into your Jetty server. That way you would not have to do it manually. I would prefer this solution to running a local Maven repository on the Jetty server as suggested by #Paul.
If you wanted to be super-clever (usually a bad idea), you might try to set up a repository directly on the machine with Jetty, that would serve the jar directly from your Jetty install. That way you would not have to modify Nexus, the jars would be only at one place. You can even set up Nexus to mirror another repository, so it could pick things up automatically.
It is a bad practice to modify .jar contents and keep the same Maven coordinates. So this "clever" approach would not work that great anyway.