java 如何在 JBoss 4.2 中强制重新编译 jsps?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/952309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:33:04  来源:igfitidea点击:

How can you force recompilation of jsps in JBoss 4.2?

javajspjbossrecompile

提问by Yishai

I hit on this nasty behavior on JBoss 4.2 in QA, and I want to nip it in the bud before we go into production and find some other corner case.

我在 QA 的 JBoss 4.2 上发现了这种令人讨厌的行为,我想在我们投入生产并找到其他一些极端情况之前将其扼杀在萌芽状态。

A jsp calles a method that had the following signature:

jsp 调用具有以下签名的方法:

 public void methodName(String arg)

This was changed to:

这被更改为:

 public void methodName(String arg, Object... args)

A pre-existing JSP called this method via:

预先存在的 JSP 通过以下方式调用此方法:

 methodName("param");

On deployment of the modified code, JBoss did not recompile the JSP and this caused a crash in QA. Adding a silly comment to the jsp fixed the problem (JBoss recognized that the JSP changed and recompiled it).

在部署修改后的代码时,JBoss 没有重新编译 JSP,这导致 QA 崩溃。向 jsp 添加一个愚蠢的注释解决了这个问题(JBoss 识别出 JSP 更改并重新编译它)。

Is there a setting on JBoss to force recompilation of JSPs on restart?

JBoss 上是否有设置在重启时强制重新编译 JSP?

EDIT: To clarify some points in the answer, the setup is that the JSPs are part of a war which is part of an ear. The ear has all classes in it, in a jar.

编辑:为了澄清答案中的一些观点,设置是 JSP 是War的一部分,是耳朵的一部分。耳朵里有所有的类,在一个罐子里。

Regarding the desire to pre-compile, if the system doesn't think that the jsp needs compilation, will pre-compile force recompilation? It doesn't seem so. The error here is not a compliation error, it is a method invocation error because of the "changed" (at the byte code level, not really at the code level) method signature.

关于预编译的愿望,如果系统认为jsp不需要编译,预编译会强制重编译吗?似乎不是这样。这里的错误不是编译错误,是方法调用错误,因为方法签名“改变了”(在字节码级别,而不是真正在代码级别)。

Addendum: Note that we experienced in production recently that even with the accepted answer's flag set the JSPs did not recompile, even though the JSP did in fact change. Major bug there, but regardless, JBoss was shutdown normally. At this point it is getting to be an old version of JBoss, but if you are still using it, deleting the content of the work and tmp directories is the only way to be sure.

附录:请注意,我们最近在生产中体验到,即使设置了已接受答案的标志,JSP 也不会重新编译,即使 JSP 确实发生了变化。那里的主要错误,但无论如何,JBoss 正常关闭。此时它已成为旧版本的 JBoss,但如果您仍在使用它,则删除 work 和 tmp 目录的内容是唯一可以确定的方法。

I'm not changing the accepted answer simply because it really gets to the point of what the question was looking for. JBoss bugs are kind of a separate issue.

我不会仅仅因为它确实达到了问题所寻找的目的而改变已接受的答案。JBoss 错误是一种单独的问题。

回答by Bert F

If the JSPs are part of a WAR that is part of an EAR that is being deployed as a jar, then I'm not clear why your JSPs are not being recompiled. Don't the JSPs in the war file have newer timestamps than their JBoss-compiled class files from the last deploy? If not, couldn't you touch the JSPs as part of building the WAR/EAR before deploying. [I'm referring to using the Unix "touch" command, not manually touching each JSP file.]

如果 JSP 是作为 jar 部署的 EAR 的一部分的 WAR 的一部分,那么我不清楚为什么没有重新编译您的 JSP。难道war 文件中的JSP 的时间戳不是比上次部署的JBoss 编译的类文件更新的时间戳吗?如果没有,您不能在部署之前将 JSP 作为构建 WAR/EAR 的一部分。[我指的是使用 Unix "touch" 命令,而不是手动触摸每个 JSP 文件。]

Alternatively, the DeleteWorkDirOnContextDestroy setting in $JBOSS/server/default/deploy/jboss-web.deployer/META-INF/jboss-service.xml may be what you are looking for. It is false by default, but setting it to true may be what you need. I think this should delete the JSPs' class files on redeploy so that they get recreated upon first access of each JSP.

或者, $JBOSS/server/default/deploy/jboss-web.deployer/META-INF/jboss-service.xml 中的 DeleteWorkDirOnContextDestroy 设置可能就是您正在寻找的。默认情况下为 false,但将其设置为 true 可能正是您所需要的。我认为这应该在重新部署时删除 JSP 的类文件,以便在第一次访问每个 JSP 时重新创建它们。

See https://jira.jboss.org/jira/browse/JBAS-3358for more info.

有关更多信息,请参阅https://jira.jboss.org/jira/browse/JBAS-3358

回答by Mr. Will

I don't know of a setting, but deleting the generated Java class file in the work directory of your JBoss instance will cause the JSP to be recompiled the next time it is called.

我不知道有什么设置,但是在 JBoss 实例的工作目录中删除生成的 Java 类文件会导致下次调用 JSP 时重新编译它。

回答by skaffman

You coudl alter the JBoss startup scripts to explicitly delete the "tmp" and/or "work" directories, where the compiled JSPs are stored. JBoss would then have no choice but to recompile them all.

您可以更改 JBoss 启动脚本以明确删除存储已编译 JSP 的“tmp”和/或“work”目录。JBoss 将别无选择,只能重新编译它们。

Not subtle, but it would do the job.

不是微妙的,但它会完成这项工作。

回答by Pablojim

One option for you would be to precompile all of your jsp's at build time. This would quickly flag any compilation errors.

一种选择是在构建时预编译所有的 jsp。这将快速标记任何编译错误。

You could also do this in production - speeding up first access but I get the feeling you want this more for a QA step than anything else. If so, you could add the precompile step to the your testing phase in your build tool of choice - and so to your CI environment. This would provide assurance that jsp's that don't compile won't make it out of test.

您也可以在生产中执行此操作 - 加快首次访问速度,但我觉得您更希望在 QA 步骤中使用它而不是其他任何东西。如果是这样,您可以将预编译步骤添加到您选择的构建工具中的测试阶段 - 以及您的 CI 环境。这将确保未编译的 jsp 不会通过测试。

See this for details on running a precompile task:

有关运行预编译任务的详细信息,请参见此处:

Jboss Jasper configuration

Jboss Jasper 配置

Hope this helps.

希望这可以帮助。

回答by RealHowTo

Some JSP containers (as per section 8.4.2 of the JSP 1.2 specification) support the capability of precompiling a JSP page.

某些 JSP 容器(按照 JSP 1.2 规范的第 8.4.2 节)支持预编译 JSP 页面的功能。

To precompile a JSP page, access the page with a query string of ?jsp_precompile

要预编译 JSP 页面,请使用 ?jsp_precompile 查询字符串访问该页面

http://hostname.com/mywebapp/mypage.jsp?jsp_precompile

The JSP page will not be executed. If the container supports precompilation, the JSP page will be compiled if necessary.

JSP 页面不会被执行。如果容器支持预编译,则必要时会编译JSP页面。

See also http://www.rgagnon.com/javadetails/java-0414.html

另见http://www.rgagnon.com/javadetails/java-0414.html

回答by Mike Pone

Pablojim is on the right track. You just need some more info to get a complete view of what's going on. Here's how I understand it.

Pablojim 走在正确的轨道上。您只需要更多信息即可全面了解正在发生的事情。这是我的理解。

In prod, you've changed a jsp that requires other jsps to be recompiled. In order for them to be recompiled one of 2 things must happen

在 prod 中,您更改了一个需要重新编译其他 jsps 的 jsp。为了让它们被重新编译,必须发生两件事之一

  1. The compiled version of the jsp needs to be deleted.
  2. The jsp itself needs to be modified (or even if it's "touched" - modified date is updated)
  1. 需要删除编译后的jsp版本。
  2. jsp本身需要修改(或者即使它被“触摸” - 修改日期被更新)

If you still need to verify that all your jsps work, they will all need to be precompiled using an ant task. this also allows you to deploy the war file with the precompiled jsps in the war file. This should solve your problem.

如果您仍然需要验证您的所有 jsps 是否正常工作,则它们都需要使用 ant task进行预编译。这也允许您使用war 文件中的预编译jsps 部署war 文件。这应该可以解决您的问题。

If your files are not deployed in a war file, but in an exploded format, you should seriously consider packaging your web appin a war file for deployment. This makes it a nice package to deploy between environments.

如果您的文件不是部署在 war 文件中,而是部署在展开的格式中,您应该认真考虑将您的 Web 应用程序打包在一个 war 文件中以进行部署。这使它成为在环境之间部署的一个很好的包。