Use Groovy to develop JFinal-4.9

1. Build Groovy development environment

https://segmentfault.com/a/11…

2. Use Groovy to develop JFinal-4.9

2.1. Development

2.1.1. The directory structure is as follows

2.1.2. Pom. XML

The < project XMLNS = "http://maven.apache.org/POM/4.0.0" XMLNS: xsi = "http://www.w3.org/2001/XMLSchema-instance" Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > com. Litongjava < / groupId > < artifactId > groovy - ee - jfinal - 4.9 - study < / artifactId > < version > 1.0 < / version > < / parent > < artifactId > groovy - ee - jfinal - 4.9 - hello < / artifactId > < build > < plugins > < plugin > < artifactId > maven -- the compiler plugin < / artifactId > < version > 3.1 < / version > < configuration > <compilerId>groovy-eclipse-compiler</compilerId> </configuration> <dependencies> <dependency> < the groupId > org. Codehaus. Groovy < / groupId > < artifactId > groovy eclipse - compiler < / artifactId > < version > 2.9.1-01 < / version > </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-batch</artifactId> </version> 3.0.8-01</version> </dependency> </plugin> <plugin> < grouppid >org.apache.maven.plugins</ grouppid > <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <includes> <include>com/**</include> <include>cn/**</include> <include>demo/**</include> </includes> <excludes> <exclude>*.txt</exclude> <exclude>*.xml</exclude> <exclude>*.properties</exclude> </excludes> </configuration> </plugin> <plugin> . < groupId > org, apache maven plugins < / groupId > < artifactId > maven - assembly - the plugin < / artifactId > < version > 3.1.0 < / version > <executions> <execution> <id>make-assembly</id> <phase>pre-integration-test</phase> <goals> <goal>single</goal> </goals>  <configuration> <! > <recompressZippedFiles>false</recompressZippedFiles> <! > <appendAssemblyId>true</appendAssemblyId> <! - pointing to the packaging description file package. XML - > < descriptors > < descriptor > SRC/main/assembly/package. XML < / descriptor > < / descriptors > <! > <outputDirectory>${project.build. Directory}/</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly plugin</artifactId> < Execution > <id>make-assembly</id> <phase>pre-integration-test</phase> <goals> <goal>single</goal> </goals> <configuration> <! > <recompressZippedFiles>false</recompressZippedFiles> <! > <appendAssemblyId>true</appendAssemblyId> <! - pointing to the packaging description file package. XML - > < descriptors > < descriptor > SRC/main/assembly/package. XML < / descriptor > < / descriptors > <! > <outputDirectory>${project.build. Directory}/</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <! -- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all --> <dependency> < the groupId > org. Codehaus. Groovy < / groupId > < artifactId > groovy -all < / artifactId > < version > 3.0.8 < / version > < type > pom < / type > </dependency> <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal-undertow</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal</artifactId> <version>4.9.12</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId> org.projectLobok </groupId> <artifactId>lombok</artifactId> <version>1.16.16</version> <scope> Provided </scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </project> </project>

2.1.3. JFinalApplication. Groovy

package com.litongjava import com.jfinal.server.undertow.UndertowServer import com.litongjava.config.AppConfig import Lombok. Extern. Slf4j. Slf4j / * * * @ the author create by ping - e - lee on the morning of July 15, 2021 3:03:59 * @ * @ desc * / @ slf4j version 1.0 class JFinalApplication { static void main(args) { long start = System.currentTimeMillis(); Create (AppConfig. Class,"undertow.properties").start() long end = System.currentTimeMillis() String message = (end - start) + "ms" System.out.println(message); //Groovy:Apparent variable 'log' was found in a static scope but doesn't refer to a local variable, static field or class. //log.info(message) } }

2.1.4. The AppConfig. Groovy

package com.litongjava.config 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. The template. The Engine / * * * @ the author create by ping - e - lee on the morning of July 15, 2021 3:00:06 * @Version 1.0 * @DESC */ class AppConfig extends JFinalConfig{@Override void ConfigConstant (Constants Me) {} @Override void configRoute(Routes me) { me.scan("com.litongjava.controller.") } @Override void configEngine(Engine me) { } @Override void configPlugin(Plugins me) { } @Override void configInterceptor(Interceptors me) { } @Override void configHandler(Handlers me) { } }

2.1.5. IndexController. Groovy

package com.litongjava.controller import com.jfinal.core.Controller import com.jfinal.core.Path import Com. Litongjava. Utils. LogUtils import groovy. Util. Logging. The Slf4j / * * * @ the author create by ping - e - lee, on July 15, 2021 3:01:07 * @version 1.0 * @desc */ @path ("/") @slf4j class IndexController extends Controller{void index() { renderText("Hello groovy") } void logClassName() { renderText(log.getClass().getName()); } void thisClassName() { renderText(this.toString()) } void thisClassLoader() { renderText(this.getClass().getClassLoader().toString()) } void exception() throws Exception { try { throw new IllegalArgumentException("This is a test") } catch (Exception e) { //e.printStackTrace(); log.error(LogUtils.getStackTraceInfo(e)) } renderText("ok") } }

2.1.6. LogUtils. Java

package com.litongjava.utils; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; /** * @author create by ping-e-lee on July 12, 2021 8:36:28 * @version 1.0 * @desc */ public class LogUtils {/** * Get the details of e.printStackTrace() and assign it to the String variable, Public static String getStackTraceInfo(Exception E) {/* public static String getStackTraceInfo(Exception E) {/* * StringWriter sw = null * StringWriter sw = null; PrintWriter pw = null; try { sw = new StringWriter(); pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); sw.flush(); return sw.toString(); } catch (Exception Ex) {return "printStackTrace() conversion error "; } finally { if (sw ! = null) { try { sw.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (pw ! = null) { pw.close(); }}}}

2.1.7. Start the JFinal project in Eclipse

Right-click the main method of jfinalApplication.groovy –>Run As–>Java Application and it starts successfully, As shown in the figure

2.1.8. View the compiled class file

2.2. The deployment

Deployment is the same as the original deployment of JFinal

2.2.1. Generate deployable artifacts

Go to groovy-ee-jfinal-4.9-hello and execute the command below

mvn clean pre-integration-test -DskipTests

Generate groovy-ee-jfinal-4.9-hello-1.0-release.tar.gz

Unpack the



The contents under the lib file are as follows

Jar ant-junit-1.10.9.jar ant-launcher-1.10.9.jar groovy-3.0.0.jar groovy-all-3.0.8.pom Groovy - ant - 3.0.8. Jar groovy - astbuilder - 3.0.8. Jar groovy cli - picocli - 3.0.8. Jar groovy - the console - 3.0.8. Jar Groovy - a datetime - 3.0.8. Jar groovy - docgenerator - 3.0.8. Jar groovy - ee - jfinal - 4.9 - hello - 1.0. Jar groovy - groovydoc - 3.0.8. Jar Jsr223-3.0.0.jar Groovy-jmx-3.0.0.jar Groovy-jsr223-3.0.0.jar Groovy-macro-3.0.0.jar Groovy-jsr223-3.0.0.jar Groovy-macro-3.0.0.jar Groovy - nio - 3.0.8. Jar groovy - servlet - 3.0.8. Jar groovy - SQL - 3.0.8. Jar groovy - swing - 3.0.8. Jar groovy - templates - 3.0.8. Jar Groovy - test - 3.0.8. Jar groovy - test - junit5-3.0.8. Jar groovy - testng - 3.0.8. Jar groovy - XML - 3.0.8. Jar Javaparser - core - 3.18.0. Jar javax.mail. Servlet - API - 4.0.1. Jar jboss - logging - 3.4.0. Final. Jar jcommander - 1.78. The jar Jfinal - 4.9.12. Jar jfinal undertow - 2.5 - jar jline - 2.14.6. Jar jquery - 3.5.1 track of. The jar junit - Jupiter - API - 5.7.0. Jar Junit - Jupiter - engine - 5.7.0. Jar junit - platform - Commons - 1.7.0. Jar junit - platform - engine - 1.7.0. Jar Junit - platform - the launcher - 1.7.0. Jar logback - classic - 1.2.3. Jar logback - core - 1.2.3. Jar opentest4j - 1.2.0. Jar Jar slf4j-api-1.7.25.jar testng-7.4.0.jar undertow -core-2.0.34.final.jar picocli-4.5.2.jar qdox-1.12.1.jar slf4j-api-1.7.25.jar testng-7.4.0.jar undertow -core-2.0.34.final.jar Undertow servlet - 2.0.34. Final. Jar xnio - API - 3.3.8. Final. The jar xnio - nio - 3.3.8. Final. The jar

2.2.2. Start the project

Executing jfinal-start.bat on Windows platform can finally call the command is

java -Xverify:none -cp config; lib\* com.litongjava.JFinalApplication

Execute successfully

2.2.3. Test

http://localhost http://localhost/thisClassName http://localhost/thisClassLoader http://localhost/exception access some interface test Test success

2.3. Code address

github

https://github.com/litongjava…

gitee

https://gitee.com/litongjava_…