# 1.3 Deploying under jfinal-undertow

# 1. Specify that the package is of type jar.

Modify the pom.xml file and change the value of the packaging tag to jar.

<packaging>jar</packaging
1

Strongly recommended: It is highly recommended to download jfinal_demo_for_maven.zip from the home page, from which you can get the pom.xml, package.xml, jfinal.sh and other configuration files and script files covered in this chapter. You can save a lot of learning cost.

# 2. Add the maven-jar-plugin plugin.

<! --
	Configuration files in a jar package have higher priority than "files of the same name" in the config directory.
	Therefore, you need to exclude the configuration files from the src/main/resources directory in the jar package, or else the config directory will not be used when deploying.
	Otherwise, the configuration file with the same name in the config directory will not take effect when deployed.
 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId
    <version>2.6</version
    <configuration
        <excludes
            <exclude>*.txt</exclude
            <exclude>*.xml</exclude
            <exclude>*.properties</exclude
            <exclude>exclude_file_name_here</exclude
            <exclude>exclude_path_here/</exclude
        </excludes
    </configuration
</plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

maven-jar-plugin is only to avoid typing the configuration file into a jar package, if it is typed into a fatjar package, you do not need to add this plugin.

# 3. Add the maven-assembly-plugin plugin

Modify pom.xml and add the maven-assembly-plugin plugin under the plugins tag as follows

<! -- 
    Use mvn clean package to package the assembly. 
    For more information, please refer to the official documentation at http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html.
-->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId
  <version>3.1.0</version>
  <executions
    <execution>
    <id>make-assembly</id>
    <phase>package</phase
    <goals
      <goal>single</goal
    </goals
 
    <configuration
      <! -- Name of the file generated by the package -->
      <finalName>${project.artifactId}</finalName
      <! -- Whether compressed files such as jar are compressed when they are packaged into zip, tar.gz, set to false to speed up packaging -->
      <recompressZippedFiles>false</recompressZippedFiles
      <! -- Whether to append the id value defined in release.xml to the generated files --> <appendAssemblyId>false</recompressZippedFiles> <!
      <appendAssemblyId>true</appendAssemblyId
      <! -- Points to the package description file package.xml -->
      <descriptors
        <descriptor>package.xml</descriptor>
      </descriptors
      <! -- Base directory for package output -->
      <outputDirectory>${project.build.directory}/</outputDirectory
      </configuration
      </execution
    </executions
</plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

maven-assembly-plugin is the official packaging plugin provided by maven, it is very functional and can be configured with many parameters for customized builds, for more detailed documentation refer to its official documentation: http://maven.apache.org/plugins/maven-assembly-plugin/ single-mojo.html

# 4. Add the package.xml file.

Add package.xml file in the root directory of the project, which is the package description file specified in the descriptor tag of the above maven-assembly-plugin, with the following contents:

<?xml version="1.0" encoding="UTF-8"? <?xml version="1.0" encoding="UTF-8"?
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
	
  <! -- assembly 
    assembly Packaging Configuration For more configuration, please refer to the official documentation:
    http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
  -->
	
  <id>release</id>
	
  <! --
      Set the format of the package, you can set multiple formats at the same time, commonly used formats are: dir, zip, tar, tar.gz.
      The dir format allows you to test the package locally.
      zip format is easy to unpack and run under windows system.
      tar, tar.gz format is easy to unpack under linux system.
  -->
  <formats
    <format>dir</format
    <format>zip</format
    <! -- <format>tar.gz</format> -->
  </formats
 
  <! -- Setting true when hitting zip generates a root directory in the zip package, setting false when hitting dir lesser directories -->
  <includeBaseDirectory>true</includeBaseDirectory
	
  <fileSets
    <! -- src/main/resources all copied to config directory -->
    <fileSet>
      <directory>${basedir}/src/main/resources</directory
      <outputDirectory>config</outputDirectory
    </fileSet
		
    <! -- src/main/webapp copy all to webapp directory -->
    <fileSet>
      <directory>${basedir}/src/main/webapp</directory>
      <outputDirectory>webapp</outputDirectory
    </fileSet
 
    <! -- Copy the script files under the project root to the root directory -->
    <fileSet>
      <directory>${basedir}</directory
      <outputDirectory>. /</outputDirectory
      <fileMode>755</fileMode
      <lineEnding>unix</lineEnding
      <includes
        <include>*.sh</include
      </includes
    </fileSet
    
    <fileSet>
      <directory>${basedir}</directory>
      <outputDirectory>. /</outputDirectory
      <fileMode>755</fileMode
      <lineEnding>windows</lineEnding
      <includes
        <include>*.bat</include
      </includes
    </fileSet>
    
  </fileSets	
 
  <! -- copy dependent jar packages to lib directory -->
  <dependencySets>
    <dependencySet
      <outputDirectory>lib</outputDirectory			
    </dependencySet> <dependencySets> <dependencySet
  </dependencySets
	
</assembly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

The packaging description file is part of the maven-assembly-plugin. The description file makes it very easy to control the details of the packaging actions. For more detailed documentation, see http://maven.apache.org/plugins/maven-assembly-plugin/assembly. html

# 5. Add the startup script to the root directory of your project.

Note: The following scripts are provided in the jfinal demo for maven project downloaded from the right side of the jfinal official home page. Copy the jfinal.sh / jfinal.bat to your own project and modify the MAIN_CLASS variable, then you can put it into use.

The Linux startup script, jfinal.sh, looks like this:

/bin/bash /bin/bash
# --------------------------------------------------------------
# /bin/bash #
# Instructions for use:
# 1: Before using this script, you need to change the MAIN_CLASS value to point to the actual startup class.
# # 1: Before using this script, you need to modify the MAIN_CLASS value to point to the actual startup class.
# 2: Use the command line . /jfinal.sh start | stop | restart to start/shutdown/restart the project.  
# /jfinal.sh start | stop | restart
# 3: JAVA_OPTS can be overridden by passing parameters like undertow.port and undertow.host via -D.
# The same values in the config file can also be found in undertow.resourcePath, undertow.ioThreads, etc. # 4: JAVA_OPTS can be overridden by passing -D to undertow.port and undertow.host,
# undertow.workerThreads can be passed in via -D, which minimizes the need to
# The need to modify the undertow configuration file is minimized
# This feature minimizes the need to # modify the undertow configuration file.
# 4: JAVA_OPTS can be passed standard java command line arguments, such as -Xms256m -Xmx1024m and other common arguments.
# 5: Function start()
# 5: The start() function gives you 4 ways to start your project on the command line, follow the hints in the comments to choose the right one.
#The function start() gives you 4 command lines to start your project.
# --------------------------------------------------------------
 
# Startup entry class, change here if this script file is used in another project.
MAIN_CLASS=com.yourpackage.YourMainClass
 
if [[ "$MAIN_CLASS" == "com.yourpackage.YourMainClass" ]]; then
    echo "Please change the value of MAIN_CLASS to your own startup class before executing this script."
	exit 0
exit 0
 
COMMAND="$1"
 
if [[ "$COMMAND" ! = "start" ]] && [[ "$COMMAND" ! = "stop" ]] && [[ "$COMMAND" ! = "restart" ]]; then
	echo "Usage: $0 start | stop | restart"
	exit 0
exit 0
 
 
# Java command line parameters, according to the need to open the following configuration, change to their own needs, pay attention to the equal sign before and after there can not be spaces
# Java_OPTS="-Xms256m -Xmx1024m -Dundertow.port=80 -Dundertow.host=0.0.0.0"
# JAVA_OPTS="-Dundertow.port=80 -Dundertow.host=0.0.0.0"
 
# Generate the class path value
APP_BASE_PATH=$(cd `dirname $0`; pwd)
CP=${APP_BASE_PATH}/config:${APP_BASE_PATH}/lib/*
 
function start()
{
    # Run as a background process and output information on the console
    java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS} &
 
    # Run as a background process and do not output information on the console
    # nohup java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS} >/dev/null 2>&1 &
 
    # Run as a background process and output the information to the output.log file
    # nohup java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS} > output.log &
 
    # run as a non-background process, mostly used in development, shortcut ctrl + c to stop the service
    # java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS}
}
 
function stop()
{
    # Support for clustered deployments
    kill `pgrep -f ${APP_BASE_PATH}` 2>/dev/null
    
    # The kill command calls the onStop() method without the -9 parameter, so it is recommended to use the -9 parameter if you don't need it.
    # kill `pgrep -f ${MAIN_CLASS}` 2>/dev/null
 
    # The following code is equivalent to the above
    # kill $(pgrep -f ${MAIN_CLASS}) 2>/dev/null
}
 
if [[ "$COMMAND" == "start" ]]; then
	start
elif [[ "$COMMAND" == "stop" ]]; then
    stop
start elif [[ "$COMMAND" == "stop" ]]; then stop
    stop
    stop elif [[ "$COMMAND == "stop" ]]; then stop else
stop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

Note that you have to change the value of the MAIN_CLASS variable in the above content according to the project's entry class, and the same applies to the jfinal.bat script on Windows.

Start the project with the command . /jfinal.sh start

Shut down the project: . /jfinal.sh stop

Restart the project: . /jfinal.sh restart

Special Note: When using the above command line, first use mvn clean package to package the project, and then use the cd command to jump to the directory of the package to execute the command. Instead of cd jumping to the root directory of the project, many people make this mistake. See the next subsection, "6. Packaging", for more information on packaging.

For the sake of space, I won't post the windows script here, you can download the jfinal demo on the right side of the homepage of the official website to get it. The latest version of the script can be downloaded here: https://gitee.com/jfinal/jfinal-undertow

How to use the windows script is as follows:

Start project command: jfinal.bat start

Close the project: jfinal.bat stop

Restart the project: jfinal.bat restart

Note: linux, mac under the script file line feed characters must be '\n', while under windows must be "\r\n", otherwise the script can not be executed, and will output unintelligible error messages, difficult to troubleshoot. How to check the line break character in the script file is shown in the document: https://www.jfinal.com/doc/1-5

Highly recommended: It is highly recommended to download jfinal_demo_for_maven.zip from the home page, from which you can get the configuration files and script files such as pom.xml, package.xml, jfinal.sh, and so on, which are covered in the above 5 subsections. Make sure you download the latest version.

# 6. Packaging

Open the command line terminal, cd command to enter the root directory of the project, and run the following command to package the project.

mvn clean package
1

After executing the above package command, the xxx.zip file will appear in the target directory under the project root, unzip the zip file with the command line . /jfinal.sh start to run it.

In addition to the zip file, a directory will be created under the target, use the command line . /jfinal.sh start to start the project. The contents of this directory are identical to the contents of the zip file.

# 7. Deployment

Upload the zip file generated by the above packing commands to the server and decompress it to complete the deployment work. The biggest advantage of developing a project based on jfinal-undertow is that you don't need to download, install, and configure a server such as tomcat.

# 8. fatjar packaging and deployment

fatjar packaging refers to the project of all classes, all resources and all jar package dependencies are packaged into a single jar package, packaged independent jar package can be easily copied, deployed, run, very suitable for microservices project development, but also very suitable for no web resources or very few web resources project!

You can download jfinal-demo-for-maven from the homepage of the official website, which has a document describing this method in detail under the doc directory, and will add the fatjar packaging method in the documentation channel.

# 9, the main advantages of jfinal-undertow

1: very fast startup, startup speed than tomcat 5 to 8 times faster. jfinal.com official website startup time within 1.5 seconds

2: Undertow is an open source product of Red Hat and is Wildfly's default web server, with a Java web server market share higher than Jetty and second only to Tomcat.

3: minimalist and subtle hot deployment design, to achieve extremely fast and lightweight hot deployment, so that the development experience to upgrade another level

4: performance is higher than tomcat, jetty, can replace tomcat, jetty for production environments

5: undertow for embedded and born , can be directly used for production environment deployment , deployment without downloading services , no need to configure services , very suitable for microservices development, deployment

6: Say goodbye to web.xml, say goodbye to tomcat, say goodbye to jetty, save a lot of packaging and deployment time. Make development, packaging, deployment become a happy thing!

7: feature-rich , support classHotSwap, WebSocket, gzip compression, servlet, filter, sessionHotSwap and other features .

8: support fatjar and non-fatjar packaging mode, easy to support microservices

9: development, packaging, deployment integration , the whole process does not need to adjust or modify any part of the project , the real realization of high-speed development from the high-speed deployment .

Last Updated: 9/17/2023, 5:25:03 AM