1

I want to connect to a Lotus Notes (8.5.3) database from my java web (Maven) project. after some searches, so in order to connect to Lotus Notes database from my java web project through CORBA DIIOP, I need to add NCSO.jar as a new dependency to my Maven Java web project. I found this link: How to add\install to maven dependency of newly created\third party jar in pom.xml, but I still cannot figure out how to make it work. I can find NCSO.jar from my local machine, but based on that link, I need to create my own repository for this file and then add it to my pom.xml file. This is my first time to add a .jar dependency to my java web project (pom.xml). In my java web project, I have EJB part hand Web part, and each has pom.xml. No sure how to add this .jar to pom.xml.

 my java IDE is built on eclipse, the current workspace structure is like this: The current workspace called: developer, it contains followings: 
 developer
    workspaces (folder)
      Java-2014prj (folder)
         .settings (folder)
         projEAR (folder) 
         projEJB (folder)
         projWeb (folder)
         src (folder)
         .project
         pom.xml

is this the correct commands? and if this is correct and no errors, what should I do after the command executed? are all POM.xml added the NCSO.jar?
c:\developer>mvn install:install-file
Dfile=c:\NCSO.jar
DgroupId=lotus
DartifactId=domino
Dversion=1.0.0
Dpackaging=.jar
DgeneratePom=true

projEAR, projEJB and projWeb each contains pom.xml as well. the NCSO.jar is located on my local c:/NCSO.jar. So I guess I should run the codes on my window command (black) screen. Should I run it on the project top folder c:\developer? or some subfolders? I do not know how to create my local repository? Can someone provide me with more details? Thanks.


Edit - the my result based on axiopisty's instructions below

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] PARENT project of MARKETPROJ
[INFO] EJB project of MARKETPROJ
[INFO] WAR project of MARKETPROJ
[INFO] EAR project of MARKETPROJ
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-install-plugin/2.4/maven-install-plugin-2.4.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-install-plugin:2.4: Plugin org.apache.maven.plugins:maven-install-plugin:2.4 o
r one of its dependencies could not be resolved: Failed to read artifact descrip
tor for org.apache.maven.plugins:maven-install-plugin:jar:2.4
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or
one of its dependencies could not be resolved: Failed to read artifact descripto
r for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-site-plugin/3.3/maven-site-plugin-3.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-site-plugin:3.3: Plugin org.apache.maven.plugins:maven-site-plugin:3.3 or one
of its dependencies could not be resolved: Failed to read artifact descriptor fo
r org.apache.maven.plugins:maven-site-plugin:jar:3.3
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or
one of its dependencies could not be resolved: Failed to read artifact descripto
r for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plu
gin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read
artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-b
eta-5
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-dependency-plugin:2.8: Plugin org.apache.maven.plugins:maven-dependency-plugin
:2.8 or one of its dependencies could not be resolved: Failed to read artifact d
escriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.8
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-release-plugin/2.3.2/maven-release-plugin-2.3.2.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-release-plugin:2.3.2: Plugin org.apache.maven.plugins:maven-release-plugin:2.3
.2 or one of its dependencies could not be resolved: Failed to read artifact des
criptor for org.apache.maven.plugins:maven-release-plugin:jar:2.3.2
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metada
ta.xml
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xm
l from/to central (https://repo.maven.apache.org/maven2): Failed to transfer fil
e: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.
xml. Return code is: 501 , ReasonPhrase:Not Implemented.
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/
to central (https://repo.maven.apache.org/maven2): Failed to transfer file: http
s://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml. Return co
de is: 501 , ReasonPhrase:Not Implemented.
[WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from h
ttps://repo.maven.apache.org/maven2 was cached in the local repository, resoluti
on will not be reattempted until the update interval of central has elapsed or u
pdates are forced. Original error: Could not transfer metadata org.apache.maven.
plugins/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2
): Failed to transfer file: https://repo.maven.apache.org/maven2/org/apache/mave
n/plugins/maven-metadata.xml. Return code is: 501 , ReasonPhrase:Not Implemented
.
[WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from https://
repo.maven.apache.org/maven2 was cached in the local repository, resolution will
 not be reattempted until the update interval of central has elapsed or updates
are forced. Original error: Could not transfer metadata org.codehaus.mojo/maven-
metadata.xml from/to central (https://repo.maven.apache.org/maven2): Failed to t
ransfer file: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metad
ata.xml. Return code is: 501 , ReasonPhrase:Not Implemented.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] PARENT project of MARKETPROJ ............................. SKIPPED
[INFO] EJB project of MARKETPROJ ................................ SKIPPED
[INFO] WAR project of MARKETPROJ ................................ SKIPPED
[INFO] EAR project of MARKETPROJ ................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.624 s
[INFO] Finished at: 2015-01-18T13:30:32-05:00
[INFO] Final Memory: 9M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'deploy' in the current project and in the pl
ugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the rep
ositories [local (C:\Users\jsmith\.m2\repository), central (https://repo.maven.apa
che.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundF
orPrefixException

********************************
**EDIT again:**
 I just checked my pom.xml again, and found we have these codes 
  <!-- local file-based repository on the team's shared drive -->
    <repository>
        <id>MARKETPROJ-repo-local</id>
        <name>MARKETPROJ File Based Internal Repository</name>
        <url>file://\\mark\mark_shrdata\MARKETPROJ\maven2\repo</url>
    </repository>
Archit
  • 3
  • 1
  • 4
smt
  • 71
  • 3
  • 10
  • If NCSO.jar is a local file jar visit : http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project – Funzzy Jan 16 '15 at 19:39
  • yes, it is a local file, I copied NCSO.jar to my local under C:/NCSO.jar, then I ran the codes as your link: but I got BUILD FAILURE, with [ERROR] The goal you specified requires a project to execute but there is no POM in this directory C:\apcke-maven-3.2.3\bin. please verify you invoked Maven from the correct directory.. Do I have to create a dumy pom in this directory? – smt Jan 16 '15 at 20:54
  • tried to copy a POM.xml to that folder C:\apcke-maven-3.2.3\bin, and run the code again, failure again. – smt Jan 16 '15 at 20:59
  • You should make your project local repository reside inside your project root directory. Then the url specified in repository section of pom.xml should be a relative url. – axiopisty Apr 14 '15 at 14:59
  • If you wanted to experiment with a tool other than maven, you could check out apache buildr. https://buildr.apache.org/quick_start.html#dependencies – axiopisty Apr 28 '15 at 19:51

2 Answers2

1

If your dependency is not available in a public repository, you'll need to install the dependency into a local maven repository. You might be tempted to install it into your ~/.m2/repository, this is the approach the other answers to this question have stated. If you do, the build will work fine for you, on that machine. But this is not the best solution. In fact, it is a bad solution because the project build is dependent on this manually installed artifact. If you delete the ~/.m2/repository directory your build will fail because the artifact won't be in the repository anymore.

If you have to install a dependency locally, it is best to install it into a project local repository, and commit the whole repository into your version control system. That way, if you share your project with anyone else, including yourself on a different machine, the build will still work for other people and they won't have to install the dependency locally too.

See here for a detailed explanation: https://devcenter.heroku.com/articles/local-maven-dependencies

For example if your project looks like this:

yourproject
+- pom.xml
+- src

Then you could create a project local repository like this:

yourproject
+- pom.xml
+- src
+- repo

And then install the dependency into the project local repository with this command:

mvn deploy:deploy-file -Durl=file:///path/to/yourproject/repo/ -Dfile=NCSO.jar -DgroupId=ncso -DartifactId=ncso -Dpackaging=jar -Dversion=1.0

So your project will now look like this:

yourproject
+- pom.xml
+- src
+- repo
   +- nsco
      +- ncso
         +- maven-metadata.xml
         +- ...
         +- 1.0
            +- ncso-1.0.jar
            +- ncso-1.0.pom
            +- ...

Then tell your project pom.xml file about your project local repository:

<repositories>
    <!--other repositories if any-->
    <repository>
        <id>project.local</id>
        <name>project</name>
        <url>file:${project.basedir}/repo</url>
    </repository>
</repositories>

And add your project local dependency to pom.xml too:

<dependency>
    <groupId>ncso</groupId>
    <artifactId>ncso</artifactId>
    <version>1.0</version>
</dependency>

EDIT - based on questions in the comments.

Assuming you have temporarily stored the dependency that needs to be deployed into your project local maven repository in the root of the C: drive, and that your project is also stored at the root of the C: drive, so your C: drive looks like this:

C:/NCSO.JAR
C:/yourproject
C:/yourproject/pom.xml
C:/yourproject/src
C:/yourproject/repo

Also assuming that you run the following command in a Command Prompt from within the root of the C: drive, then this would be the command you would use to install the dependency into your project local repository:

C:\> mvn deploy:deploy-file -Durl=file:///C:/yourproject/repo/ -Dfile=NCSO.jar -DgroupId=ncso -DartifactId=ncso -Dpackaging=jar -Dversion=1.0

After you have run this command successfully, you can then delete the file C:/NCSO.jar. It is no longer needed because it has been installed (duplicated) into your project local repository. At this point, you would also add C:/yourproject/repo, and all of its data, into your version control system so the repo folder and all of the data inside of it becomes a permanent part of your project.

axiopisty
  • 4,972
  • 8
  • 44
  • 73
  • thank you so much for the detailed info, actually, that is my concerns since we have a big java team on this java web project at same time, I must make sure the dependency I added works for other developers after I committed my codes in eclipse, in your codes,-Durl=file:///path/to/yourproject/repo/, how to apply it to my situation? when should I commit my codes to svn? should I commit it after the last step you mentioned? I must be cautious to avoid crashing the system and make it works for myself before I commit to svn. – smt Jan 18 '15 at 05:29
  • and this command: mvn deploy:deploy-file -Durl=file....., which directory should I ran this codes? should I run it under "developer" path (like c:\developer>mvn deploye:deploy-file -Durl=file... ...)or somewhere else? – smt Jan 18 '15 at 05:32
  • Please see the EDIT I made to my original answer. I included specific details to answer your questions in these comments. Please don't forget to up vote the answer and mark it as the accepted answer after you see that it works and is the solution you're looking for. Cheers. – axiopisty Jan 18 '15 at 06:25
  • please refer my EDIT in my original post to see my result, it seems I have more problem to deploy based on your instruction, please let me know if there is any issue for my running environment. – smt Jan 18 '15 at 19:01
  • please also refer my second EDIT, I found the repo in my pom.xml, so it seems I have problem to deploy to produce ncso.jar to my local repo, can I physically copy the NCSO.jar to that share drive (folder) instead of using the deploy approach to move the NSCO.jar to my local repo folder ? – smt Jan 18 '15 at 19:25
  • I don't understand what the problem is. You should describe in your question what you have tried, what the specific problem is that you're having (in your own words), and ask a specific question that you want answered about that problem. If the problem is different from your original question you should mark this question as answered, and post a new question. Generally you shouldn't change your original question as the problem morphs. – axiopisty Jan 18 '15 at 23:00
  • You didn't show what command you typed in the command line to generate the output you specified in the edited answer. Also, please notice that you should not change the URL as specified in the section of pom.xml. In other words, the repository url should be a relative path, relative to the project base directory like this: file:${project.basedir}/repo. Don't modify the ${project.basedir}. That part should remain the same. – axiopisty Jan 18 '15 at 23:04
  • I did not change the URL as specified in the section of pom.xml, I have not tried that part yet. Basically, I have not successfully installed dependency to local repository yet. those error messages was happened after I tried your codes of : C:\> mvn deploy:deploy-file -Durl=file:///C:/yourproject/repo/ -Dfile=NCSO.jar -DgroupId=ncso -DartifactId=ncso -Dpackaging=jar -Dversion=1.0 – smt Jan 18 '15 at 23:55
  • The codes shows on my second EDIT which shows repository section was found on my pom.xml file which is not added by me this time, it was there before, I just let you know to see if I can use it based on my this request. that is used for you reference only. – smt Jan 18 '15 at 23:59
  • Again, see here for a detailed explanation: https://devcenter.heroku.com/articles/local-maven-dependencies – axiopisty Apr 14 '15 at 15:02
0

Using the cmd prompt or terminal, you mvn install the jar as your link suggested so that it'll be created in your .m2 repository and then just add as follow to your pom.xml

In cmd prompt or terimal:

mvn install:install-file -Dfile="path-to-jar-file" -DgroupId=com.project.ncso -DartifactId=ncso -Dversion=1.0.0 -Dpackaging=jar

In your pom.xml inside the project directory add the following:

<dependency>
        <groupId>com.project.ncso</groupId>
        <artifactId>ncso</artifactId>
        <version>1.0.0</version>
    </dependency>
Derick
  • 11
  • 7
  • please read my prevoius response, it does not work. any idea? – smt Jan 16 '15 at 21:00
  • What do you mean by it doesn't work? Where is your project? There should be a pom.xml in your project directory – Derick Jan 16 '15 at 21:15
  • Project directory as in the directory that includes your java web project. You shouldn't be running the project from C:\apcke-maven-3.2.3\bin that's the binary location for maven itself – Derick Jan 16 '15 at 21:18
  • The project is built on eclipse, the current workspace "developer:"contains .settings folder, EAR folder, EJB folder, Web folder, src folder with pom.xml. these are parallel on main folder, but if I open Web folder or EJB folder or EAR folder, they all have POM.xml as well. so I do not know where and how to run the codes on window command window? Should I run it on the top folder ? or some sub-folders? could you show me specific how to run the codes? – smt Jan 18 '15 at 04:21
  • I have updated my original post, please refer it and let me know if you need more information, thanks – smt Jan 18 '15 at 04:48
  • no sure how .m2 repository work in my local? can you explain in details? is there any .jar created there and I copy it to somewhere of my java project ? – smt Jan 18 '15 at 04:56
  • as "axiopisty" mentioned in his response, since I should not use this approach , we have a big java team and work together for this java project, I need make sure the dependency I added works for everybody else. any comments? – smt Jan 18 '15 at 05:34
  • I'm not sure if this is the correct way to do it, but you can technically copy your local .m2 (the one installed when you installed maven) and copy that to your project base Java_2014prj and then make sure you change repository URL of all your pom.xml to that one. – Derick Jan 19 '15 at 18:26
  • The error you're getting is probably because the dependencies you needed aren't in the folders. Also, when you're adding the nsco.jar reference to your pom.xml, just add to the pom.xml of the project that depends on the library. You don't need to add to every single sub projects if you the project doesn't need it. – Derick Jan 19 '15 at 18:29