os-maven-plugin
is a Maven extension/plugin that generates various useful platform-dependent project properties normalized from ${os.name}
and ${os.arch}
.
${os.name}
and ${os.arch}
are often subtly different between JVM and operating system versions or they sometimes contain machine-unfriendly characters such as whitespaces. This plugin tries to remove such fragmentation so that you can determine the current operating system and architecture reliably.
os-maven-plugin
detects the name of the current operating system and normalizes it into more generic one.
os.detected.name
aix
hpux
os400
linux
osx
freebsd
openbsd
netbsd
sunos
windows
os-maven-plugin
also detects the architecture of the current operating system and normalizes it into more generic one.
os.detected.arch
x86_64
x86_32
itanium_64
sparc_32
sparc_64
arm_32
aarch_64
ppc_32
ppc_64
You can also use the ${os.detected.classifier}
property, which is a shortcut of ${os.detected.name}-${os.detected.arch}
.
Add the extension to your pom.xml
like the following:
<project>
<build>
<extensions>
<plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.2.3.Final</version>
</extension>
</extensions>
</build>
</project>
Use ${os.detected.classifier}
as the classifier of the dependency:
<project>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>my-native-library</artifactId>
<version>1.0.0</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
</dependencies>
</project>
Use ${os.detected.classifier}
as the classifier of the produced JAR:
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${os.detected.classifier}</classifier>
</configuration>
</plugin>
</plugins>
</build>
</project>
If you are using IntelliJ IDEA, you should not have any problem.
If you are using Eclipse, you need to install an additional Eclipse plugin because m2e does not evaluate the extension specified in a pom.xml
. Download os-maven-plugin-1.2.3.Final.jar
and put it into the <ECLIPSE_HOME>/plugins
directory.
(As you might have noticed, os-maven-plugin
is a Maven extension, a Maven plugin, and an Eclipse plugin.)
If you are using other IDEs such as NetBeans, you need to set the system properties os-maven-plugin
sets manually when your IDE is launched. You usually use JVM's -D
flags like the following:
-Dos.detected.name=linux -Dos.detected.arch=x86_64 -Dos.detected.classifier=linux-x86_64