Ant unzip / unwar with the same directory name as the file name

I need to unzip the war file in the tomcat / webapps directory using the ANT build script. The name of the war file is not fixed. How can I unzip it in a directory whose name matches the name of a war file. I know how to unzip a file, but the problem is that it unpacks the contents in the specified destination directory. What if I do not know the directory name?

before assembly:

tomcat/webapps/
   myApp-0.1.war

after assembly:

tomcat/webapps
   myApp-0.1/
   myApp-0.1.war
+3
source share
2 answers

Good bluetech work . Your decision can also be expressed as follows:

<target name="unwar-test">
  <property name="webapps.dir" value="tomcat/webapps" />

  <fileset id="war.file.id" dir="${basedir}"
      includes="${webapps.dir}/myApp-*.war" />
  <property name="war.file" refid="war.file.id" />

  <basename property="war.basename" file="${war.file}" suffix=".war" />
  <property name="unwar.dir" location="${webapps.dir}/${war.basename}" />
  <mkdir dir="${unwar.dir}" />
  <unwar dest="${unwar.dir}" src="${war.file}" />
</target>
+2
source

So, after learning about some Ant tasks, here's what I came up with:

<!-- Get the path of the war file. I know the file name pattern in this case -->
<path id="warFilePath">
    <fileset dir="./tomcat/webapps/">
        <include name="myApp-*.war"/>
    </fileset>
</path>

<property name="warFile" refid="warFilePath" />

<!-- Get file name without extension -->
<basename property="warFilename" file="${warFile}" suffix=".war" />

<!-- Create directory with the same name as the war file name -->
<mkdir dir="./tomcat/webapps/${warFilename}" />

<!-- unzip war file -->
<unwar dest="./tomcat/webapps/${warFilename}">
    <fileset dir="./tomcat/webapps/">
        <include name="${warFilename}.war"/>    
    </fileset>
</unwar>

, . stackoverflow ant -contrib, .

+2

Source: https://habr.com/ru/post/1780026/


All Articles