Detect OS and Java on Windows and Linux


Question

I have a JavaFX project based on Maven. I want to build the Maven project on Windows and on Linux. In order to automate the process when I deploy the bundle I want to automatically detect the operating system.

In windows I have this configuration:

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
            </plugin>

But on Linux I have this configuration:

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <bootclasspath>/opt/java/lib/jfxrt.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
            </plugin>

Can I somehow set the Java usage based on the operating system on which the bundle is deployed?

1
1
8/2/2013 11:50:17 AM

Accepted Answer

You can use profiles for such purposes like this:

<profiles>
  <profile>
    <activation>
      <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
      </os>
    </activation>
    ...
  </profile>
</profiles>
4
8/2/2013 11:06:25 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon