Maven2: use $ {basedir} in jar path

I use an external, patented jar in my project. When I hard code the path as follows in my pom.xml, it works fine:

<dependency>
  <groupId>com.foo.bar</groupId>
  <artifactId>bar</artifactId>
  <version>5.2</version>
  <scope>system</scope>
  <type>jar</type>
  <systemPath>D:\workspace\myproj\external\companyname\lib\proprietary_api.jar</systemPath>
</dependency>

However, when I try to use the $ {basedir} variable, maven cannot find the jar:

<dependency>
  <groupId>com.foo.bar</groupId>
  <artifactId>bar</artifactId>
  <version>5.2</version>
  <scope>system</scope>
  <type>jar</type>
  <systemPath>${basedir}\external\companyname\lib\proprietary_api.jar</systemPath>
</dependency>

POM is located in the folder D: \ workspace \ myproj

It should also be cross-platform compatible (dev on Windows, deployment on Linux).

Thank!

+3
source share
5 answers

Incorrect use of the system area for your own JARs. You must deploy or install it in a local / central repository.

+4
source

, , forward (/) (\) . , mvn -e mvn -X ( ) - .

:

${basedir} , .

Btw, mvn install:install-file systemPath? :

+3

- ${file.separator} .

+3
  • .

  • ${basedir} Maven. , ${basedir} (.. , Maven ), .

0

, linux, . , , .

jarPath ( ) .

Maven Profiles

View the OS tag and profile configuration tag. Make sure your assembly is always portable and less manual steps are required. Accepted.

0
source

Source: https://habr.com/ru/post/1776371/


All Articles