How can I get a temporary folder on the machine maven is running on?

I want to save some unpacked files to a temporary folder of the machine.

Question . How to get a temporary folder using maven?

Question . Will it work both in linux environment and in windows?

+4
source share
2 answers

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

java.io.tmpdir Default temporary file path

As an 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>

Pay attention to the element outputDirectoryand its meaning.


, target Maven , .


Linux Windows?

, Java, , .

+7

java- tmp dir - java.io.tmpdir maven ${java.io.tmpdir} .

, :

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

All Articles