如何在 Tomcat 中启用 Java 断言 [英] How can I enable java assertions in Tomcat

查看:30
本文介绍了如何在 Tomcat 中启用 Java 断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 Spring web 应用程序中使用 Java assert 关键字,主要是在我的域类上(检查构造函数中的不变量),但我看不到如何启用运行时断言检查.

I would like to use the Java assert keyword in my Spring web-app, primarily on my domain classes (checking invariants within constructors), but I cannot see how to enable runtime assertion checking.

对于普通的 java 应用程序,我会在 java 命令中使用 -ea 开关,但我不知道如何使用 Tomcat 等来做到这一点.

For a normal java application, I would use the -ea switch with the java command, but I don't see how I can do that with Tomcat, etc.

这是推荐的东西,还是我应该使用 Spring 框架中的Assert"类?然而,我宁愿让我的域类不受 Spring 依赖.

Is this the recommended thing, or should I use the "Assert" class from the Spring framework? I'd rather keep my domain classes free of Spring dependencies, however.

推荐答案

对于tomcat,在JAVA_OPTS中添加-ea(所有java进程都启动了),甚至更好CATALINA_OPTS(仅适用于网络应用引擎).

For tomcat, add -ea to JAVA_OPTS (all java processes started), or even better to CATALINA_OPTS (only to web app engine).

阅读文件 catalina.batcatalina.sh 以获取有关 JAVA_OPTSCATALINA_OPTS 的更多信息.

Read the files catalina.bat or catalina.sh for more information on JAVA_OPTS and CATALINA_OPTS.

已编辑:感谢来自 @Joachim

这篇关于如何在 Tomcat 中启用 Java 断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆