How can I get the temp folder of a machine running maven? How can I get the temp folder of a machine running maven? linux linux

How can I get the temp folder of a machine running maven?


Maven supports, as part of the default properties, any Java System property, hence you can use the following property:

java.io.tmpdir Default temp file path

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.


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.


Will it work on both linux and windows environments?

Yes, since it is Java property, it is supposed to be OS independent.


use the java environment tmp dir - java.io.tmpdiryou can access it from maven via ${java.io.tmpdir} without having to predefine it.

you can also customize it on a specific run by running:

mvn clean install -Djava.io.tmpdir=/tmp/where/ever