-1

My project is in maven. I decided to bring ojdbc14.jar into my project rather than keeping it in tomcat/lib folder. So I installed ojdbc14.jar in my local repository by using mvn install:install-file. But as i understood now that it is best to move it to lib folder because of memory leeks by jdbc driver as already discussed here tomcat - memeory-leak. But problem is I am using some classes that are importing from this ojdbc14.jar. E.g. :

import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.driver.OracleConnection;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.jdbc.driver.OracleResultSet;
import oracle.sql.BLOB;
import oracle.sql.CLOB;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;

How can I remove my ojdbc14.jar from project and move it to lib folder and still be able to access this class in code without compile errors?

Community
  • 1
  • 1
Akhil
  • 533
  • 2
  • 11
  • 26
  • While there is an maven command you can execute to do this, it's easier to just delete the files manually from the repository.Like this on windows Documents and Settings\your username\.m2 or $home/.m2 on Linux – Rajesh Feb 18 '15 at 05:50

2 Answers2

0

What you want is maven scope provided. Since you already put ojdbc14.jar to your tomcat lib folder, it is now no different than any other tomcat provided library, for example servlets.

provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

See example usage here, note that for your case, you need to add provided to this syntax also. You need to install this jar to your maven repository as explained here.

Community
  • 1
  • 1
Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
0

compile: This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

provided: This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

runtime: This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

test: This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

system: This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

import: (only available in Maven 2.0.9 or later) This scope is only used on a dependency of type pom in the section. It indicates that the specified POM should be replaced with the dependencies in that POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

As per you requirement you have you added maven dependency like as

<dependency>
   <groupId>com.oracle</groupId>
   <artifactId>ojdbc14</artifactId>
   <version>10.2.0.2.0</version>
   <scope>provided</provided>
</dependency>

so runtime server will look for the resource from JDK or server libraries

Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74