XWiki启动和停止脚本配置优化完整教程

2024-06-21 李腾 75 次阅读 0 次点赞
本文针对Windows环境下XWiki启动和停止脚本的常见问题提供完整解决方案。详细讲解如何通过添加chcp 65001解决中文乱码问题,修改JETTY_PORT和JETTY_STOP_PORT处理端口占用,配置JAVA_PATH指定JDK21路径避免环境变量冲突,以及注释PAUSE命令确保Windows服务正常运行。提供完整的start_xwiki.bat和stop_xwiki.bat脚本修改示例,帮助用户快速完成XWiki环境配置优化。

在windows上,xwiki的启动和结束脚本有一些小问题,例如中文乱码,在脚本开头添加@chcp 65001即可解决。xwiki默认端口是8080,停止端口是8079,如果你电脑上这两个端口被占用的话,可以分别修改start_xwiki.bat和stop_xwiki.bat中的JETTY_PORT和JETTY_STOP_PORT设置。xwiki 16.8要求jdk版本较高,默认使用环境变量中的jdk。如果你环境变量中的jdk版本较低(例如jdk8),建议另外安装一个jdk21,不设置环境变量,在脚本中直接设置JAVA_PATH指定jdk路径即可。如果你把xwiki创建成了windows服务,需要把两个脚本最后pause注释掉,要不启动和停止服务时一直pending。

这里我把修改后的start_xwiki.bat和stop_xwiki.bat发布出来,仅供参考,可以使用Beyond Compare对照一下,看看原文件和修改后的新文件有哪些区别。

start_xwiki.bat

1、添加@chcp 65001,设置编码为utf-8。

2、将set JETTY_PORT=8080改为set JETTY_PORT=9900,修改访问端口为9900。

3、添加set JAVA_PATH=%~~dp0jdk-21.0.2\bin\java.exe,设置JAVA_PATH为jdk21。

4、将最后的PAUSE改为REM PAUSE,避免停止Windows服务时,一直停止不掉。

@echo off
@chcp 65001
REM -------------------------------------------------------------------------
REM See the NOTICE file distributed with this work for additional
REM information regarding copyright ownership.
REM
REM This is free software; you can redistribute it and/or modify it
REM under the terms of the GNU Lesser General Public License as
REM published by the Free Software Foundation; either version 2.1 of
REM the License, or (at your option) any later version.
REM
REM This software is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
REM Lesser General Public License for more details.
REM
REM You should have received a copy of the GNU Lesser General Public
REM License along with this software; if not, write to the Free
REM Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
REM 02110-1301 USA, or see the FSF site: http://www.fsf.org.
REM -------------------------------------------------------------------------

REM -------------------------------------------------------------------------
REM Optional ENV vars
REM -----------------
REM   XWIKI_OPTS - parameters passed to the Java VM when running Jetty
REM     e.g. to increase the memory allocated to the JVM to 1GB, use
REM       set XWIKI_OPTS=-Xmx1024m
REM   JETTY_OPTS - optional parameters passed to Jetty's start.jar. For example to list the configuration that will
REM       execute, try setting it to "--list-config". See
REM       http://www.eclipse.org/jetty/documentation/current/start-jar.html for more options.
REM   JETTY_PORT - the port on which to start Jetty, 8080 by default
REM   JETTY_STOP_PORT - the port on which Jetty listens for a Stop command, 8079 by default
REM -------------------------------------------------------------------------

setlocal EnableDelayedExpansion

if not defined XWIKI_OPTS set XWIKI_OPTS=-Xmx1024m

REM The port on which to start Jetty can be defined in an environment variable called JETTY_PORT
if not defined JETTY_PORT (
  REM Alternatively, it can be passed to this script as the first argument
  set JETTY_PORT=%1
  if not defined JETTY_PORT (
    set JETTY_PORT=9900
  )
)

REM The port on which Jetty listens for a Stop command can be defined in an environment variable called JETTY_STOP_PORT
if not defined JETTY_STOP_PORT (
  REM Alternatively, it can be passed to this script as the second argument
  set JETTY_STOP_PORT=%2
  if not defined JETTY_STOP_PORT (
    set JETTY_STOP_PORT=8079
  )
)

REM Discover java.exe from the latest properly installed JRE
REM for /f tokens^=2^ delims^=^" %%i in ('reg query HKEY_CLASSES_ROOT\jarfile\shell\open\command /ve') do set JAVAW_PATH=%%i
REM set JAVA_PATH=%JAVAW_PATH:\javaw.exe=%\java.exe
REM if "%JAVA_PATH%"=="" set JAVA_PATH=java
REM Handle the case when JAVA_HOME is set by the user
REM if not "%JAVA_HOME%" == "" set JAVA_PATH=%JAVA_HOME%\bin\java.exe
set JAVA_PATH=%~dp0jdk-21.0.2\bin\java.exe

REM TODO: Remove once https://jira.xwiki.org/browse/XCOMMONS-2852 is fixed. In summary we need this to allow the XWiki
REM code or 3rd party code to use reflection to access private variables (setAccessible() calls).
REM See https://tinyurl.com/tdhkn6mp
set XWIKI_OPENS_LANG=--add-opens java.base/java.lang=ALL-UNNAMED
set XWIKI_OPENS_IO=--add-opens java.base/java.io=ALL-UNNAMED
set XWIKI_OPENS_UTIL=--add-opens java.base/java.util=ALL-UNNAMED
set XWIKI_OPENS_CONCURRENT=--add-opens java.base/java.util.concurrent=ALL-UNNAMED
set XWIKI_OPTS=%XWIKI_OPENS_LANG% %XWIKI_OPENS_IO% %XWIKI_OPENS_UTIL% %XWIKI_OPENS_CONCURRENT% %XWIKI_OPTS%

REM Location where XWiki stores generated data and where database files are.
set XWIKI_DATA_DIR=C:/Users/liteng/OneDrive/xwiki/data
set XWIKI_OPTS=%XWIKI_OPTS% -Dxwiki.data.dir="%XWIKI_DATA_DIR%"

REM Catch any Out Of Memory to make easier to analyze it
set XWIKI_OPTS=%XWIKI_OPTS% -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="%XWIKI_DATA_DIR%"

REM Ensure the data directory exists so that XWiki can use it for storing permanent data.
if not exist "%XWIKI_DATA_DIR%" mkdir "%XWIKI_DATA_DIR%"

REM Ensure the logs directory exists as otherwise Jetty reports an error
if not exist "%XWIKI_DATA_DIR%\logs" mkdir "%XWIKI_DATA_DIR%\logs"

REM Set up the Jetty Base directory (used for custom Jetty configuration) to be the current directory where this file
REM is.
REM Also make sure the log directory exists since Jetty won't create it.
set JETTY_BASE=.
if not exist "%JETTY_BASE%\logs" mkdir "%JETTY_BASE%\logs"

REM Specify Jetty's home and base directories
set JETTY_HOME=jetty
set XWIKI_OPTS=%XWIKI_OPTS% -Djetty.home="%JETTY_HOME%" -Djetty.base="%JETTY_BASE%"

REM Specify the encoding to use
set XWIKI_OPTS=%XWIKI_OPTS% -Dfile.encoding=UTF8

REM Specify port on which HTTP requests will be handled
set JETTY_OPTS=%JETTY_OPTS% jetty.http.port=%JETTY_PORT%
REM In order to print a nice friendly message to the user when Jetty has finished loading the XWiki webapp, we pass
REM the port we use as a System Property
set XWIKI_OPTS=%XWIKI_OPTS% -Djetty.http.port=%JETTY_PORT%

REM Specify port and key to stop a running Jetty instance
set JETTY_OPTS=%JETTY_OPTS% STOP.KEY=xwiki STOP.PORT=%JETTY_STOP_PORT%

"%JAVA_PATH%" %XWIKI_OPTS% %3 %4 %5 %6 %7 %8 %9 -jar "%JETTY_HOME%/start.jar" %JETTY_OPTS%

REM Pause so that the command window used to run this script doesn't close automatically in case of problem
REM (like when the JDK/JRE is not installed)
REM PAUSE

stop_xwiki.bat

1、添加set JAVA_PATH=%~~dp0jdk-21.0.2\bin\java.exe,设置JAVA_PATH为jdk21。

2、将最后的PAUSE改为REM PAUSE,避免停止Windows服务时,一直停止不掉。

@echo off
REM -------------------------------------------------------------------------
REM See the NOTICE file distributed with this work for additional
REM information regarding copyright ownership.
REM
REM This is free software; you can redistribute it and/or modify it
REM under the terms of the GNU Lesser General Public License as
REM published by the Free Software Foundation; either version 2.1 of
REM the License, or (at your option) any later version.
REM
REM This software is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
REM Lesser General Public License for more details.
REM
REM You should have received a copy of the GNU Lesser General Public
REM License along with this software; if not, write to the Free
REM Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
REM 02110-1301 USA, or see the FSF site: http://www.fsf.org.
REM -------------------------------------------------------------------------

REM The port on which Jetty listens for a Stop command can be defined in an environment variable called JETTY_STOP_PORT
if not defined JETTY_STOP_PORT (
  REM Alternatively, it can be passed to this script as the first argument
  set JETTY_STOP_PORT=%1
  if not defined JETTY_STOP_PORT (
    set JETTY_STOP_PORT=8079
  )
)

REM Discover java.exe from the latest properly installed JRE
REM for /f tokens^=2^ delims^=^" %%i in ('reg query HKEY_CLASSES_ROOT\jarfile\shell\open\command /ve') do set JAVAW_PATH=%%i
REM set JAVA_PATH=%JAVAW_PATH:\javaw.exe=%\java.exe
REM if "%JAVA_PATH%"=="" set JAVA_PATH=java
REM Handle the case when JAVA_HOME is set by the user
REM if not "%JAVA_HOME%" == "" set JAVA_PATH=%JAVA_HOME%\bin\java.exe
set JAVA_PATH=%~dp0jdk-21.0.2\bin\java.exe

REM Location where XWiki stores generated data and where database files are.
REM set XWIKI_DATA_DIR=${xwikiDataDir}
set XWIKI_DATA_DIR=C:/Users/liteng/OneDrive/xwiki/data

REM Specify Jetty's home and base directories
set JETTY_HOME=jetty
set JETTY_BASE=.
set XWIKI_OPTS=%XWIKI_OPTS% -Djetty.home="%JETTY_HOME%" -Djetty.base="%JETTY_BASE%"

REM Specify port and key to stop a running Jetty instance
set JETTY_OPTS=%JETTY_OPTS% STOP.KEY=xwiki STOP.PORT=%JETTY_STOP_PORT%

"%JAVA_PATH%" %XWIKI_OPTS% -jar "%JETTY_HOME%/start.jar" --stop %JETTY_OPTS%

REM Pause so that the command window used to run this script doesn't close automatically in case of problem
REM (like when the JDK/JRE is not installed)
REM PAUSE
本文由人工编写,AI优化,转载请注明原文地址: XWiki启动和停止脚本修改指南:解决中文乱码、端口占用和JDK配置

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!