10

I have created a Maven Project in Eclipse (EE Developer Kepler version) and I have in my pom.xml file the following error, "Missing artifact com.oracle:ojdbc7:jar:12.1.0.1" in this code

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.1</version>
</dependency>

I know that I have to add the jdbc repository into my .m2 folder. I have done so by downloading the ojdbc7.jar from the following link http://www.oracle.com/technetwork/database/features/jdbc/jdbc-drivers-12c-download-1958347.html

With that archive donwloaded, I open a terminal (I have Debian installed) and run the following command as root

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7  
-Dversion=12.1.0.1 -Dpackaging=jar -Dfile=ojdbc7.jar -DgeneratePom=true

After that, I got as an output BUILD SUCCESS, and if I go to the .m2 folder I see in the com->oracle->ojdbc7 two files called "ojdbc7-12.1.0.1.jar.lastUpdated" and "ojdbc7-12.1.0.1.pom.lastUpdated" but still Eclipse brings me the code into the pom.xml file as an error

What can I do to fix this?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
a.ras2002
  • 385
  • 2
  • 7
  • 21
  • 1
    You probably just need to do "Maven > Update Project", see here http://stackoverflow.com/questions/20546962/what-does-maven-update-project-do-in-eclipse – Tunaki Jun 28 '16 at 09:18

3 Answers3

2

If you are using eclipse, go to the folder where you have your pom and try this commands:

mvn -Declipse.workspace=<path-to-your-eclipse-workspace> eclipse:add-maven-repo
mvn eclipse:eclipse

I haven't tried it in Linux, but it should fix your dependencies / eclipse path issues.

robertoia
  • 2,301
  • 23
  • 29
  • Thanks! I've run those commands and now my pom.xml error has gone away! But now I have another error "Dynamic Web Module 3.0 requires Java 1.6 or newer" any idea on how to solve this? – a.ras2002 Apr 09 '14 at 16:04
  • @a.ras2002 It looks like you have a old version of the jre (<1.6). A quick google search returns [this](http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0-requires-java-1-6-or-newer-in-maven-projects/), but I dont' really know. – robertoia Apr 09 '14 at 16:08
  • I have done that, and also the following, rightclick project-> remove maven nature. Then in a terminal run this command "mvn eclipse:clean" and finally delete the project in eclipse (but do not delete the sources) and import the project again. With all of that the project now is finally errors-free – a.ras2002 Apr 09 '14 at 17:02
  • @Roberto I am facing the same issue and after running this command I am getting this error "[ERROR] Could not find goal 'add-maven-repo' in plugin org.apache.maven.plugins: maven-eclipse-plugin:2.10 among available goals clean, configure-workspace, eclipse, help, install-plugins, myeclipse, myeclipse-clean, rad, rad-clean, remove-cache, resolve-workspace-dependencies, to-maven -> [Help 1]" . – Vicky Oct 27 '17 at 07:21
2
  1. From the menu, select "Window-->Show View-->Other..."
  2. In the dialog, select "Maven-->Maven Repositories" and hit OK.
  3. In the Maven Repositories view, right-click "Local Repositories-->Local Repository" and select "Rebuild Index" from the popup menu. If asked if you're sure you want to rebuild the index, hit OK.

If that doesn't work (it should), try right-clicking the project in the Explorer view, selecting "Maven-->Update Project..." from the popup menu, ensuring that "Update dependencies" is checked in the dialog that appears, and hitting OK.

BTW, you probably want to add <scope>runtime</scope> to your dependency element in the pom file, although that's not related to your issue.

Alvin Thompson
  • 5,388
  • 3
  • 26
  • 39
  • 1
    Nothing, I've done what you've said but the error is still showing... thanks anyway! – a.ras2002 Apr 09 '14 at 15:49
  • Interesting--the "Update Project" dialog does the same thing as the `mvm eclipse:eclipse` command above. The `eclipse:add-maven-repo` command is deprecated and is no longer necessary, so that did nothing. In the dialog, the "Update Project configuration from pom.xml" should be checked by default. Did you uncheck it? – Alvin Thompson Apr 09 '14 at 19:08
  • In any case, neither of those commands effect Eclipse's index of the local repository. Since Eclipse IIRC refreshes your workspace when it regains focus, I'm guessing that when you went to the command line and back again it refreshed your workspace, and that's what made the problem appear to go away at that time. – Alvin Thompson Apr 09 '14 at 19:12
  • I don't know why the error went away... As you said the Update Project is the same thing as `mvn eclipse:eclipse` And in the dialog, the "Update Project configuration from pom.xml" is checked... so I don't know why that error went away when I did what @RobertoIzquierdo told me, but that happens.... just one quick question, why you told me to add `runtime` to my dependency element? (yes I'm a total newbie in Maven and J2EE) – a.ras2002 Apr 10 '14 at 09:00
  • The `runtime` scope means that the library is only needed at runtime, and not when compiling. That is, the jar won't be added to your class path when compiling your code, but it will be added to the class path when running the compiled code. Since the driver merely implements the JDBC API and doesn't provide any publicly available classes (that you should be using), it's not needed when compiling. If you exclude it when compiling, Eclipse will be more efficient since it doesn't have to parse the jar and add what it finds to code completion. – Alvin Thompson Apr 10 '14 at 14:08
  • It also ensures that you don't inadvertently use classes that are exposed by the driver in your code. That would cause your code to only work with Oracle databases, and possibly only with that version. – Alvin Thompson Apr 10 '14 at 14:12
  • Ok, understood then. Thanks a lot for the help and the advice! – a.ras2002 Apr 10 '14 at 14:30
2

There is another choice for the Oracle JDBC drivers, that is not perfect, because it requires to be registered in the maven repository from Oracle, but it does not need the mvn install:install-file step.

Check the steps to set it up here:

Peter Gibbons
  • 406
  • 4
  • 8