java - Can I add jars to maven 2 build classpath without installing them? -
maven2 driving me crazy during experimentation / quick , dirty mock-up phase of development.
i have pom.xml
file defines dependencies web-app framework want use, , can generate starter projects file. however, want link 3rd party library doesn't have pom.xml
file defined, rather create pom.xml
file 3rd party lib hand , install it, , add dependency pom.xml
, tell maven: "in addition defined dependencies, include jars in /lib
too."
it seems ought simple, if is, missing something.
any pointers on how appreciated. short of that, if there simple way point maven /lib
directory , create pom.xml
enclosed jars mapped single dependency name / install , link in 1 fell swoop suffice.
problems of popular approaches
most of answers you'll find around internet suggest either install dependency local repository or specify "system" scope in pom
, distribute dependency source of project. both of these solutions flawed.
why shouldn't apply "install local repo" approach
when install dependency local repository remains there. distribution artifact fine long has access repository. problem in cases repository reside on local machine, there'll no way resolve dependency on other machine. making artifact depend on specific machine not way handle things. otherwise dependency have locally installed on every machine working project not better.
why shouldn't apply "system scope" approach
the jars depend on "system scope" approach neither installed repository or attached target packages. that's why distribution package won't have way resolve dependency when used. believe reason why use of system scope got deprecated. anyway don't want rely on deprecated feature.
the static in-project repository solution
after putting in pom
:
<repository> <id>repo</id> <releases> <enabled>true</enabled> <checksumpolicy>ignore</checksumpolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <url>file://${project.basedir}/repo</url> </repository>
for each artifact group id of form x.y.z
maven include following location inside project dir in search artifacts:
repo/ | - x/ | | - y/ | | | - z/ | | | | - ${artifactid}/ | | | | | - ${version}/ | | | | | | - ${artifactid}-${version}.jar
to elaborate more on can read this blog post.
use maven install project repo
instead of creating structure hand recommend use maven plugin install jars artifacts. so, install artifact in-project repository under repo
folder execute:
mvn install:install-file -dlocalrepositorypath=repo -dcreatechecksum=true -dpackaging=jar -dfile=[your-jar] -dgroupid=[...] -dartifactid=[...] -dversion=[...]
if you'll choose approach you'll able simplify repository declaration in pom
to:
<repository> <id>repo</id> <url>file://${project.basedir}/repo</url> </repository>
a helper script
since executing installation command each lib kinda annoying , error prone, i've created utility script automatically installs jars lib
folder project repository, while automatically resolving metadata (groupid, artifactid , etc.) names of files. script prints out dependencies xml copy-paste in pom
.
include dependencies in target package
when you'll have in-project repository created you'll have solved problem of distributing dependencies of project source, since project's target artifact depend on non-published jars, when you'll install repository have unresolvable dependencies.
to beat problem suggest include these dependencies in target package. can either assembly plugin or better onejar plugin. official documentaion on onejar easy grasp.
Comments
Post a Comment