Skip to content

Commit

Permalink
ant target and shell scripts to repackage the war
Browse files Browse the repository at this point in the history
  • Loading branch information
lolocohen committed Jun 29, 2018
1 parent d39aa9c commit 3c412f5
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,6 +1,6 @@
/.metadata/
/x-*/
*.txt
*.bat
/*.bat
*.zip
/.recommenders/
34 changes: 34 additions & 0 deletions admin-web/build.xml
Expand Up @@ -139,6 +139,40 @@
<echo message="${war.name}.war file created in '${build.dir}' directory"/>
</target>

<!-- =====================================================================-->
<!-- Repackage the WAR file by adding jar files to its WEB-INF/lib folder -->
<!-- =====================================================================-->

<!--
Usage: ant -Ddir=<root_jars_directory> -Djars="<include_patterns>" war.update
-->
<target name="war.update" depends="">
<echo message="creating the ${war.name}.war WAR file..."/>
<update.war srcdir="${dir}" includes="${jars}"/>
<echo message="${war.name}.war file updated in '${build.dir}' directory"/>
</target>

<!--
Add one or more jars in the .war file's WEB-INF/lib directory.
Parameters:
- dest: the war file to update, defaults to './build/jppf-admin-web-<jppf-version>.war'
- srcdir: the root directory from which to get the jars, defaults to '.'
- includes: one or more comma-spearted Ant include patterns, relative to srcdir
example: "lib1/*.jar,**/my*.jar"
-->
<macrodef name="update.war">
<attribute name="dest" default="${build.dir}/${war.name}.war"/>
<attribute name="srcdir" default="${basedir}"/>
<attribute name="includes"/>
<sequential>
<echo message="updating war with dest=@{dest}, dir=@{srcdir}, includes=@{includes}"/>
<war warfile="@{dest}" update="true" needxmlfile="false">
<lib dir="@{srcdir}" includes="@{includes}"/>
</war>
</sequential>
</macrodef>


<!-- ========================================================================= -->
<!-- Generate the Maven artifacts -->
<!-- ========================================================================= -->
Expand Down
39 changes: 39 additions & 0 deletions admin-web/repackage.bat
@@ -0,0 +1,39 @@
@echo off

::--------------------------------------------------------------------------------
:: Repackage a war file by adding specified jars in its WEB-INF/lib directory
::
:: Parameters:
:: - %1 is the path to the war file to repackage
:: example: build/jppf-admin-web-6.0.war
:: - all subsequent parameters specify the path to one or more jars to add
:: Wildcards * and ? are allowed
:: example: C:\jppf\lib\mylib.jar C:\jppf\lib2\*.jar
::
:: Full example usage:
:: repackage build\jppf-admin-web-6.0.war C:\jppf\lib\mylib.jar C:\jppf\lib2\*.jar
::--------------------------------------------------------------------------------

set current_dir=%~dp0


rmdir /S /Q %current_dir%tmp > nul
mkdir %current_dir%\tmp\WEB-INF\lib

echo copying jar files to %current_dir%tmp\WEB-INF\lib

for %%x in (%*) do (
if NOT "%1"=="%%x" (
for %%g in (%%x) do (
copy %%g %current_dir%tmp\WEB-INF\lib > nul
)
)
)

echo updating %1

call jar uf %1 -C %current_dir%tmp .

rmdir /S /Q %current_dir%tmp > nul

echo done
34 changes: 34 additions & 0 deletions admin-web/repackage.sh
@@ -0,0 +1,34 @@
#! /bin/sh

#-----------------------------------------------------------------------------------
# Repackage a war file by adding specified jars in its WEB-INF/lib directory
#
# Parameters:
# - $1 is the path to the war file to repackage
# example: build/jppf-admin-web-6.0.war
# - all subsequent parameters specify the path to one or more jars to add
# Wildcards * and ? are allowed
# example: ~/jppf/lib/mylib.jar ~/jppf/lib2/*.jar
#
# Full example usage:
# ./repackage.sh build/jppf-admin-web-6.0.war ~/jppf/lib/mylib.jar ~/jppf/lib2/*.jar
#-----------------------------------------------------------------------------------

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

rm -rf "$current_dir"
mkdir -p "$current_dir"/tmp/WEB-INF/lib

echo copying jar files to $current_dir/tmp/WEB-INF/lib

for p in $*; do
if "$p" != $1
cp $p "$current_dir"/tmp/WEB-INF/lib
fi
done

echo updating $1

jar uf $1 -C $current_dir/tmp .

rm -rf $current_dir

0 comments on commit 3c412f5

Please sign in to comment.