从maven获取JRE

时间:2018-03-16 18:15:21

标签: java maven

是否仍然可以从maven下载JRE作为zip文件,以便可以将其包含在打包产品中?我找到了这个代码,它不再起作用了:

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>compile</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.oracle</groupId>
                  <artifactId>jre</artifactId>
                  <version>1.8.141</version>
                  <type>zip</type>
                  <classifier>windows-i586</classifier>
                  <outputDirectory>${basedir}</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

更新:看起来这样的事情只有在将zip文件上传到自己的maven repo之后才能工作......

1 个答案:

答案 0 :(得分:1)

将版本1.8.141更改为1.8.0_131latest maven只有这个:

<!-- https://mvnrepository.com/artifact/com.oracle.java/jre -->
<dependency>
    <groupId>com.oracle.java</groupId>
    <artifactId>jre</artifactId>
    <version>1.8.0_131</version>
</dependency>

编辑:根据OP的评论

  

此处的示例是针对依赖项的。我需要的是一个maven的目标   将解压缩的JRE复制到文件夹。实际上我确实需要一个特定的JRE   版。所以目前,解决方案是安装JRE zip文件   我的maven repo并用maven目标打开它。

Maven Dependency Plugin

可以将jre工件复制并解压缩到其他位置
<project>
  [...]
  <dependencies>
    <dependency>
        <groupId>com.oracle.java</groupId>
        <artifactId>jre</artifactId>
        <version>1.8.0_131</version>
    </dependency>
  </dependencies>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>validate</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.oracle.java</groupId>
                  <artifactId>jre</artifactId>
                  <type>zip</type>
                  <outputDirectory>/path/to/alternateLocation</outputDirectory>
                </artifactItem>
              </artifactItems>
             </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>