java - 是否可以将 JVM 选项存储在文件中?
问题描述
我有一个在 AWS Elastic Beanstalk 或我的本地机器上运行的 Tomcat 应用程序。
每当我想启动应用程序时,我都必须-Dkey=value
向它传递许多选项。
这些选项的值取决于我运行的环境(例如,dev、prod、staging 或 qa,...)。
是否可以将这些选项集存储在一个文件中(比如说qa.properties
,dev.properties
或prod.properties
, ...),以便我可以将类似的东西传递-property_file=dev.properties
给 JVM 以在开发环境中启动 java 应用程序?
传递-property_file=dev.prperties
给 JVM 比传递-Ddev_key1=dev_value1 -Ddev_key2=dev_value2 -Ddev_key3=dev_value3 ...
给 JVM 更优雅。
我在java -help
.
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
解决方案
在启动 tomcat 执行之前$CATALINA_HOME/bin/setenv.sh
(或%CATALINA_BASE%\bin\setenv.bat
用于 Windows)
你可以写setenv.sh
文件
export JAVA_OPTS="$JAVA_OPTS\
-Ddev_key1=dev_value1\
-Ddev_key2=dev_value2\
-Ddev_key3=dev_value3"
推荐阅读
- python - 有没有办法将 openpyxl 行(存储在列表中)写入新的 Excel 文件?
- c# - 从 DB2 视图中获取数据
- html - 返回顶部锚链接的偏移量
- javascript - 如何将逻辑和状态从主要组件拆分到多个文件
- ios - 无法使用 CGPDFDocumentCreateWithURL 读取 PDF 文档
- javascript - 在 Javascript 烧瓶模板中处理 Python 字典时遇到问题
- apache-beam - 运行 Apache Beam Python SplittableDoFn 时出错
- javascript - 在点击 url 提示时使用 app Html 网页打开
- encoding - 将 GStreamer 管道编码和复用到 MPEG-TS
- python - 如何打开和显示来自 github 存储库的图像