Reputation: 1306
I'm trying to specify an external jar using systemPath and specifying a scope of system
<dependency>
<groupId>org.whatever</groupId>
<artifactId>jar-name</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${pom.basedir}/libs/foo.jar</systemPath>
</dependency>
This allows the project to build, but I get runtime errors that make me believe that the jars are not being included as a runtime dependency.
The doc says
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. A dependency with this scope is added to the classpath used for compilation and test, but not the runtime classpath. It is not transitive.
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.
How do I make sure that the artifact is available at runtime? It's still there, in the same location as specified (I'm doing all this on one system.). Using IntelliJ, if that makes a difference
I tried doing this by specifying a project-repository, via
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
But in that case, I couldn't even get the project to build. The dependencies were not found at all. I used mvn install:install-file
to install the jars into the libs directory, but it still wouldn't work.
I also tried simply installing to my local repo also using mvn install:install-file
. But I get compile errors. It is not finding the repos at all, although I'm not getting any errors other than the compile errors. I confirmed that the jars were installed properly in the .m2 repo
Upvotes: 2
Views: 3925
Reputation: 1306
This is resolved. It was user error. I thought that the Jar I was adding was a drop-in replacement. But the compiler errors were caused by imports having to change. I thought it wasn't picking up the jars properly. Thanks to the people to helped. You at least steered me in the right direction.
Upvotes: 0
Reputation: 746
You are using pom.basedir
instead of project.basedir
in systemPath
.
The system
scope is deprecated in Maven.
So you should consider using the maven-install-plugin
plugin and install the required jar locally. The install plugin will install the jar file to your local repository the ~/.m2/repository
so you can use it in your local builds.
You should use the install:install-file
goal to install a file from command line.
Upvotes: 2