JFinal summary

Self JFinal summary

Introduction: Each time you build ssm framework, like moving, like, very complicated, and prone to error. Just learned JFinal minimalist, eliminating the need to use the process in the record here to learn.

Thanks: Thank you very much for this tutorial published on the website, very detailed, are interested can see more, taught the process. . . . . https://www.jfinal.com/doc/1-3

Text start it!

First, build JFinal items:

  1. Create a maven project, choose An archetype which contains a sample Maven Webapp project.

2.pom file to the dependent jar package:

        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal-undertow</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal</artifactId>
            <version>4.3</version>
        </dependency>

3. Add the specified jdk1.8 the plugin, the plugin needs to be placed <build> <plugins> under (mainly reminded not misplaced, do not understand it at Baidu)

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

 4. Create a configuration class

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;

public class DemoConfig extends JFinalConfig {

    public static void main(String[] args) {
        UndertowServer.start(DemoConfig.class, 80, true);
    }

    public void configConstant(Constants me) {
        me.setDevMode(true);
    }

    public void configRoute(Routes me) {
        me.add("/hello", HelloController.class);
    }

    public void configEngine(Engine me) {
    }

    public void configPlugin(Plugins me) {
    }

    public void configInterceptor(Interceptors me) {
    }

    public void configHandler(Handlers me) {
    }
}

The controller generates a

import com.jfinal.core.Controller;

public class HelloController extends Controller {
    public void index() {
       renderText("Hello JFinal World.");
    }
}

6. Run the main method, direct access 127.0.0.1/hello to see the effect. So far simple JFinal is now fully set is quick and easy! ! ! ! ! !

Second, the package is a jar package or generate quick start mode

1.JFinal default jetty, without the use of tomcat! ! ! Back when running the main method that is run in a container! !

2. Add about maven pom file jar packaging configuration (without any changes, it can be added directly to the plugins)

            <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>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <Version> 3.1.0 </ Version></recompressZippedFiles>
                <executions>
                    <Execution> 
                        <ID> the make-Assembly </ ID> 
                        <Phase> Package </ Phase> 
                        <Goals> 
                            <Goal> SINGLE </ Goal> 
                        </ Goals> 
                        <Configuration> 
                            <-! packed generated file name - > 
                            <a finalName> project.artifactId $ {} </ a finalName> 
                            <-! like compressed JAR file are packed into the zip, tar.gz whether compression is set to false to accelerate the speed of packing -> 
                            <recompressZippedFiles> false
                            <! - package file is generated to be added release.xml id values defined -> 
                            <appendAssemblyId> to true </ appendAssemblyId> 
                            <! - package profile points Package .xml -> 
                            <descriptors> 
                                <descriptor> the package.xml </ descriptor> 
                            </ descriptors> 
                            <-! packed result output from the base directory -> 
                            <the outputDirectory> $ {project.build.directory} / </ the outputDirectory> 
                        </ Configuration> 
                    </ Execution> 
                </executions>
            </plugin>

3. Create package.xml (consistent with the red font 2) in the project root directory, the root directory is the project level, project name directory (such as JFinalTest project, the root directory is the JFinalTest /).

tip: to note here, my profile is under the windows, so the packaging format is zip (red font at), if it is under linux, will be revised to zip tar.gz

<Assembly xmlns = "http://maven.apache.org/ASSEMBLY/2.0.0" 
    xmlns: the xsi = "http://www.w3.org/2001/XMLSchema-instance" 
    the xsi: the schemaLocation = "HTTP: / http://maven.apache.org/xsd/assembly-2.0.0.xsd /maven.apache.org/ASSEMBLY/2.0.0 "> 
    ! <- Assembly pack configure more configuration, see the lawsuit party documentation: http : // maven.apache.org/plugins/maven-assembly-plugin/assembly.html -> 
    <ID> Release </ ID> 
    ! <- set packaging format, which can set a variety of formats, format commonly used: dir, zip, tar, tar.gz dir packed format facilitates local test results zip format facilitates 
        extracting run tar windows system, tar.gz format facilitates extracting run linux system -> 
    <formats> <the format> zip </ the format > 
        <-! <format> tar.gz </ format> ->
    </ Formats> 
    <-! zip is set to play true
        When the zip is generated in a root package, is set to play the dir to false low level directory -> 
    <includeBaseDirectory> to true </ includeBaseDirectory> 

    <FileSets> 
        <-! The src / main / Resources config directory to copy all -> 
        <the fileSet> 
            <directory> $ the basedir} {/ the src / main / Resources </ directory> 
            <the outputDirectory> config </ the outputDirectory> 
        </ the fileSet> 
        <-! the src / main / webapp webapp directory to copy all -> 
        <the fileSet> 
            <Directory> $ the basedir} {/ the src / main / the webapp </ Directory> 
            <the outputDirectory> the webapp </ the outputDirectory> 
        </ the fileSet> 

        <!- Project root file copy the following script to the root directory -> 
        <fileSet>
            <Directory> $ {basedir} </ Directory> 
            <outputDirectory> </ outputDirectory> 
            <-! script file permissions set to 755 under linux, no need to chmod can be run directly -> 
            <the fileMode> 755 </ the fileMode> 
            < Includes> 
                . <the include> * SH </ the include> 
                . <the include> BAT * </ the include> 
            </ Includes> 
        </ the fileSet> 
    </ FileSets> 
    <-! dependent jar package lib directory to copy -> 
    <dependencySets> 
        <the dependencySet> 
            <the outputDirectory> lib </ the outputDirectory> 
        </ the dependencySet> 
    </ dependencySets>
</assembly>

4. I'm a developer in eclipse, first of all maven update, and then perform the clean, final implementation package (cmd can also go directly under the project directory, mvn clean package), it will eventually generate a zip bag and jar files in the target directory.

5. Generate the start.bat (or the start.sh) files! The following batch only need to program red font can be changed to their main class . Note that this is bat file under windows.

Use : to extract the zip package generated after the program .bat put under a directory (e.g. JFinalTest items, into the .bat JFinalTest / down), and then start to run in cmd start.bat

OFF @echo 

REM ---------------------------------------------- --------------------------- 
REM 
REM instructions: 
REM 
REM 1 only need to modify MAIN_CLASS when the script for another project: run 
rem 
rem 2: by the JAVA_OPTS - D and passing undertow.port undertow.host such parameters covering 
the same value in the configuration file rem addition undertow.resourcePath, undertow.ioThreads 
rem undertow.workerThreads total of five parameters can be - D for the incoming 
REM 
REM . 3: may be the JAVA_OPTS standard java incoming command line parameters, e.g. -Xms256m - Xmx1024m such common parameters 
REM 
REM 
REM ------------------ -------------------------------------------------- ----- 

setlocal & pushd


To change this time rem start entry class, the script file for other projects 
the SET MAIN_CLASS = com.chx.test.DemoConfig
 
rem the Java command line parameters, open the following configuration needed to change their own needs, pay attention to before and after the equal sign No spaces 
REM the SET "the JAVA_OPTS = -Xms256m -Xmx1024m -Dundertow.port = 80 -Dundertow.host = 0.0.0.0" 
REM the SET "-Dundertow.port the JAVA_OPTS = = = 80 -Dundertow.host 0.0.0.0" IF "% 1 "==" Start " GOTO Normal
 IF "% 1 "==" STOP " GOTO Normal
 IF "% 1 "==" restart " GOTO Normal GOTO error 
: error 
echo Usage: jfinal.bat Start | STOP | restart
 GOTO : EOF 
:normalif "%1"=="start" 









goto start
if "%1"=="stop" goto stop
if "%1"=="restart" goto restart
goto :eof


:start
set APP_BASE_PATH=%~dp0
set CP=%APP_BASE_PATH%config;%APP_BASE_PATH%lib\*
echo starting jfinal undertow
java -Xverify:none %JAVA_OPTS% -cp %CP% %MAIN_CLASS%
goto :eof


:stop
set "PATH=%JAVA_HOME%\bin;%PATH%"
echo stopping jfinal undertow
for /f "tokens=1" %%i in ('jps -l ^| find "%MAIN_CLASS%"') do ( taskkill /F /PID %%i )
goto :eof


:restart
call :stop
call :start
goto :eof

endlocal & popd
pause

sh files under Linux : the following red font to their main class. Files are placed above and the same location, perform ./start.sh start

#! / bin / bash 
# ------------------------------------------- --------------------------- 
# name: jfinal.sh 
# Version:       1.0 
# author: yangfuhai 
# Email: [email protected] 
# 
# Description: 
# 1 : the need to modify the script before using MAIN_CLASS value to point to the actual start of class 
# 
# 2: use the command line ./jfinal.sh start | stop | restart to start / close / restart project   
# 
# 3: JAVA_OPTS by - D passing undertow.port covered with such parameters undertow.host 
same value # profile addition undertow.resourcePath, undertow.ioThreads, 
# undertow.workerThreads by a total of five parameters -  D were passed, the function to minimize the
# the need to modify the undertow profile 
#
# . 4: the JAVA_OPTS can be passed standard java command line parameters, e.g. -Xms256m - Xmx1024m Such common parameters 
# 
# 5: start () function is given 4 are two actuation command line program, according to choose appropriate annotation tips way 
# 
# ---------------------------------------------- ------------------------ 

# boot entry class, we have to change here in the script file for other projects 
MAIN_CLASS = com.yourpackage.YourMainClass 

IF [ [ "$ MAIN_CLASS" == "com.yourpackage.YourMainClass" ]]; the then 
    echo "please modify MAIN_CLASS value of your project start Class, and then execute the script." 
    Exit 0 
fi 

the COMMAND = "$ 1" IF start"]] && [[ "$ COMMAND"! = "stop"]] &&[[ "$COMMAND" != "restart" ]]; then

! [! [ "$ The COMMAND" = "Start"]] && [! [ "$ The COMMAND" = "STOP"]] && [[ "$ the COMMAND" = "restart" 
    echo "Usage: $ 0 Start | STOP | restart" 
    Exit 0 
fi 


# the Java command line parameters, open the following configuration needed, we need to change, there are no spaces around the equal sign 
# the JAVA_OPTS = "- Xms256m -Xmx1024m -Dundertow.port = 80 -Dundertow.host = 0.0. 0.0 " 
# the JAVA_OPTS =" - 80 -Dundertow.host = 0.0.0.0 Dundertow.port = " 

# generated class path value 
APP_BASE_PATH = $ ($ 0 dirname CD` `; pwd) 
the CP = $ {APP_BASE_PATH} / config:APP_BASE_PATH} {$ / lib / * 

function Start () 
{ 
    # run as a background process, and output in the console 
    java -Xverify: none $ {JAVA_OPTS} -cp $ {CP} $ {MAIN_CLASS} &
 
    # running as a background process, and does not output the console 
    # nohup java -Xverify: none $ { JAVA_OPTS} -cp $ {CP} MAIN_CLASS} {$> / dev / null 2> &. 1 & 

    # runs as a background process, and outputs the information to a file output.log 
    # Java -Xverify the nohup: none $ the JAVA_OPTS -cp $ {} {} $ {MAIN_CLASS the CP}> output.log & 

    # run non-daemon, used for the development phase, the shortcut key ctrl + c to stop the service 
    # java -Xverify: none $ {JAVA_OPTS } -cp the CP} {$ {$ MAIN_CLASS} 
} 

function STOP () 
{ 
    # support cluster deployment 
    kill `pgrep -f $ {APP_BASE_PATH} ` 2> / dev / null 
    
    when no command # kill -9 argument, the callback will onStop () method , determined that no callback parameters recommended -9 
    # `the kill MAIN_CLASS the pgrep -f $ {}` 2> / dev / null 

    # is equivalent to the following code with the code above 
    # kill $ (pgrep -f $ { MAIN_CLASS}) 2> / dev / null 
} 

IF [[ "$ the COMMAND" == "Start"]]; the then 
    Start 
elif [[ "$ the COMMAND" == "STOP"]];then
    stop
else
    stop
    start
fi

 

Guess you like

Origin www.cnblogs.com/chxwkx/p/11275423.html