[英]How can I get the temp folder of a machine running maven?
I'd like to save some unpacked files into the temp folder of a machine. 我想将一些解压缩的文件保存到计算机的临时文件夹中。
Question : How can I get the temp folder using maven? 问题 :如何使用maven获取临时文件夹?
Question : Will it work on both linux and windows environments? 问题 :它是否适用于Linux和Windows环境?
Maven supports , as part of the default properties, any Java System property , hence you can use the following property: 作为默认属性的一部分,Maven 支持任何Java System属性 ,因此您可以使用以下属性:
java.io.tmpdir
Default temp file pathjava.io.tmpdir
默认临时文件路径
As example: 例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<!-- further conf here -->
<outputDirectory>${java.io.tmpdir}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Note the outputDirectory
element and its value. 请注意
outputDirectory
元素及其值。
As a further note, also note that the target
folder of the Maven build is also meant to host temporary files, so you should also consider to use it for such a purpose. 另请注意,还要注意Maven构建的
target
文件夹也用于承载临时文件,因此您还应考虑将其用于此目的。
Will it work on both linux and windows environments?
它适用于Linux和Windows环境吗?
Yes, since it is Java property, it is supposed to be OS independent. 是的,因为它是Java属性,它应该是独立于操作系统的。
use the java environment tmp dir - java.io.tmpdir
you can access it from maven via ${java.io.tmpdir}
without having to predefine it. 使用java环境tmp dir -
java.io.tmpdir
你可以通过${java.io.tmpdir}
从maven访问它,而不必预先定义它。
you can also customize it on a specific run by running: 您还可以通过运行在特定运行中自定义它:
mvn clean install -Djava.io.tmpdir=/tmp/where/ever
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.