How do I get the temporary file from a machine that works with maven?

advertisements

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?

Question: Will it work on both linux and windows environments?


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.