• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

maven: How t include third party library to existing maven project

 
Kacee Saxena
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to include external jar to my existing maven project. I used following command to install it to local maven repository:


mvn -e install:install -Dfile="D:\test\com.project.MyApp.externalLib-1.0.jar" -DgroupId=com.project -DartifactId=MyApp -Dversion=1.0 -Dpackaging=jar

and got following exception:

org.apache.maven.lifecycle.LifecycleExecutionException: The packaging for this p
roject did not assign a file to the build artifact

at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: The packaging for thi
s project did not assign a file to the build artifact
at org.apache.maven.plugin.install.InstallMojo.execute(InstallMojo.java:
124)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:694)
... 17 more

What needs to be done in this case ? I am not getting any useful articles on internet as well.

Basic question : It "should" be possible to add a third party non maven library to a maven project. Is this correct ?

Also, what can I check to have this working ?

Thanks,
Kacee

 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using forward slashes (/) instead of backwards slashes (\) in the file name.
 
Kacee Saxena
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter. But now I'm gettign this error:

D:\>mvn -e install:install -Dfile="D:/test/com.project.MyApp.externalLib-1.0.jar" -DgroupId=com.project -DartifactId=MyApp -Dversion=1.0 -Dpackaging=jar

+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'install'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [install:install]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: install. It requires a project with an existing pom.
xml, but the build is not using one.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Cannot execute mojo: ins
tall. It requires a project with an existing pom.xml, but the build is not using
one.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot execute mojo:
install. It requires a project with an existing pom.xml, but the build is not us
ing one.
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:414)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:694)
... 17 more

Do i need to create pom.xml in my "MyApp" project ? Is that really so ?? If yes, how can i create pom.xml with minimal addition ?
 
Kacee Saxena
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting forward slashes did not work.

The above error :

org.apache.maven.lifecycle.LifecycleExecutionException: Cannot execute mojo: ins
tall. It requires a project with an existing pom.xml, but the build is not using
one.

got resolved by running the mvn install command from the existing Maven project, as it took its pom.xml.

But however, m back to same point :
org.apache.maven.lifecycle.LifecycleExecutionException: The packaging for this p
roject did not assign a file to the build artifact

Please help.
 
Kacee Saxena
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I solved my problem.

I had a common maven repository and an interface to operate on that repository. That interface could also generate POM.xml for the third-party library I wanted to add, and my job was done.

So after all this, I have concluded

Any third-party library needs to have pom.xml file.
Not sure about its content.

Anyone, please add to this post, if there are any other ways to do this.

Thanks,
Kacee
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never noticed that before, but it does appear that you have to run "mvn install:install" from a project directory where that directory contains a POM. I'm not sure why because the "install:install" directive doesn't even use the POM. I guess that I have never run into this situation because what I do is build the POM for my project, including its dependencies. Then if Maven doesn't find a dependency, it gives an error with the suggestion for running "insert:insert". I then copy-paste the suggested command and supply the path to the JAR, so the POM is already available.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic