maven generates executable jar s and runs them using shell scripts

To create maven project and use maven project to generate executable jar, you need to use maven assembly plugin plug-in to complete. The configuration of pom.xml file is as follows

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""




After the above configuration is completed, package the project into war, and then execute it with the following command in the cmd command

java -Xms512m -Xmx1024m -jar D:/jar/helloworld-jar-with-dependencies.jar

If there are parameters, you can add your parameters later. The author uploaded the jar package to the linux server and executed it in the way of shell script, which is as follows

start_time=`date +%s`
java -Xms512m -Xmx1024m -jar /root/jar/helloworld-jar-with-dependencies.jar
end_time=`date +%s`
echo -e "\n exec jar takes ${elapse_time} seconds\n"

Execute the following sh command to run the shell script, and the result is as follows

Hello World...

 exec jar takes 0 seconds

Tags: Maven Apache xml Java

Posted on Sat, 02 May 2020 10:15:02 -0700 by SuisydeKing