Jfinal 入门案件及遇到的问题二

Jfinal 入门案件及遇到的问题二

jfinal-undertow 下部署

  1. 指定打包为类型为 jar
<packaging>jar</packaging>
  1. 添加 maven-jar-plugin 插件
<!--
	jar 包中的配置文件优先级高于 config 目录下的 "同名文件"
	因此,打包时需要排除掉 jar 包中来自 src/main/resources 目录的
	配置文件,否则部署时 config 目录中的同名配置文件不会生效
 -->
<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>
  1. 添加 maven-assembly-plugin 插件

修改 pom.xml ,在其中的 plugins 标签下面添加如下 maven-assembly-plugin 插件

<!-- 
    使用 mvn clean package 打包 
    更多配置可参考官司方文档: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>
      <!-- 打包生成的文件名 -->
      <finalName>${project.artifactId}</finalName>
      <!-- jar 等压缩文件在被打包进入 zip、tar.gz 时是否压缩,设置为 false 可加快打包速度 -->
      <recompressZippedFiles>false</recompressZippedFiles>
      <!-- 打包生成的文件是否要追加 release.xml 中定义的 id 值 -->
      <appendAssemblyId>true</appendAssemblyId>
      <!-- 指向打包描述文件 package.xml -->
      <descriptors>
        <descriptor>package.xml</descriptor>
      </descriptors>
      <!-- 打包结果输出的基础目录 -->
      <outputDirectory>${project.build.directory}/</outputDirectory>
      </configuration>
      </execution>
    </executions>
</plugin>
  1. 添加 package.xml 文件

在项目根目录下面添加 package.xml,该文件是在上述 maven-assembly-plugin 在 descriptor 标签中指定的打包描述文件

<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 打包配置更多配置可参考官司方文档:
    http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
  -->
	
  <id>release</id>
	
  <!--
      设置打包格式,可同时设置多种格式,常用格式有:dir、zip、tar、tar.gz
      dir 格式便于在本地测试打包结果
      zip 格式便于 windows 系统下解压运行
      tar、tar.gz 格式便于 linux 系统下解压运行
  -->
  <formats>
    <format>dir</format>
    <format>zip</format>
    <!-- <format>tar.gz</format> -->
  </formats>
 
  <!-- 打 zip 设置为 true 时,会在 zip 包中生成一个根目录,打 dir 时设置为 false 少层目录 -->
  <includeBaseDirectory>true</includeBaseDirectory>
	
  <fileSets>
    <!-- src/main/resources 全部 copy 到 config 目录下 -->
    <fileSet>
      <directory>${basedir}/src/main/resources</directory>
      <outputDirectory>config</outputDirectory>
    </fileSet>
		
    <!-- src/main/webapp 全部 copy 到 webapp 目录下 -->
    <fileSet>
      <directory>${basedir}/src/main/webapp</directory>
      <outputDirectory>webapp</outputDirectory>
    </fileSet>
 
    <!-- 项目根下面的脚本文件 copy 到根目录下 -->
    <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>	
 
  <!-- 依赖的 jar 包 copy 到 lib 目录下 -->
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>			
    </dependencySet>
  </dependencySets>
	
</assembly>
  1. 在项目根目录下面添加启动脚本

以下脚本文件在 jfinal 官网首页右侧下载的 jfinal demo for maven 项目中已经提供,复制其中的 jfinal.bat 到自己的项目中修改 MAIN_CLASS 变量值,即可投入使用

# 启动入口类,该脚本文件用于别的项目时要改这里
MAIN_CLASS=com.yourpackage.YourMainClass
 
if [[ "$MAIN_CLASS" == "com.yourpackage.YourMainClass" ]]; then
    echo "请先修改 MAIN_CLASS 的值为你自己项目启动Class,然后再执行此脚本。"
	exit 0
fi
 
COMMAND="$1"
 
if [[ "$COMMAND" != "start" ]] && [[ "$COMMAND" != "stop" ]] && [[ "$COMMAND" != "restart" ]]; then
	echo "Usage: $0 start | stop | restart"
	exit 0
fi
 
 
# Java 命令行参数,根据需要开启下面的配置,改成自己需要的,注意等号前后不能有空格
# JAVA_OPTS="-Xms256m -Xmx1024m -Dundertow.port=80 -Dundertow.host=0.0.0.0"
# JAVA_OPTS="-Dundertow.port=80 -Dundertow.host=0.0.0.0"
 
# 生成 class path 值
APP_BASE_PATH=$(cd `dirname $0`; pwd)
CP=${APP_BASE_PATH}/config:${APP_BASE_PATH}/lib/*
 
function start()
{
    # 运行为后台进程,并在控制台输出信息
    java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS} &
 
    # 运行为后台进程,并且不在控制台输出信息
    # nohup java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS} >/dev/null 2>&1 &
 
    # 运行为后台进程,并且将信息输出到 output.log 文件
    # nohup java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS} > output.log &
 
    # 运行为非后台进程,多用于开发阶段,快捷键 ctrl + c 可停止服务
    # java -Xverify:none ${JAVA_OPTS} -cp ${CP} ${MAIN_CLASS}
}
 
function stop()
{
    # 支持集群部署
    kill `pgrep -f ${APP_BASE_PATH}` 2>/dev/null
    
    # kill 命令不使用 -9 参数时,会回调 onStop() 方法,确定不需要此回调建议使用 -9 参数
    # kill `pgrep -f ${MAIN_CLASS}` 2>/dev/null
 
    # 以下代码与上述代码等价
    # kill $(pgrep -f ${MAIN_CLASS}) 2>/dev/null
}
 
if [[ "$COMMAND" == "start" ]]; then
	start
elif [[ "$COMMAND" == "stop" ]]; then
    stop
else
    stop
    start
fi
  1. 打包(遇到许多问题,大多数maven配置问题)

打开命令行终端,cd 命令进入项目根目录,运行以下命令即可打包
mvn clean package

问题总结

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project JfianlDemo: Compilation failure: Compilation failure:
[ERROR] 不再支持源选项 5。请使用 6 或更高版本。
[ERROR] 不再支持目标选项 1.5。请使用 1.6 或更高版本。

解决方法:
这个问题都是你的jdk版本过低,我的因为没有配置好,导致的报错。
参考人家的,可以完美解决问题

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project JfianlDemo: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

这个没有创建web.xml文件,创建即可webapp/WEB-INF/web.xml
可以参考我的包结构
JfinalDeno结构图

猜你喜欢

转载自blog.csdn.net/NewDay_/article/details/108416300