是否可以将 .class(java) 文件单独添加到现有的 .war 文件中?
我有一个Example.war 文件,它没有该war 文件的src 代码。但我想对example.war 文件更改一些内容。所以我创建了新页面(.java 文件)并通过 ant 编译了该页面。它已成功构建。现在我想将新页面(.class 文件)附加到 Example.war。我刚刚打开了 example.war 文件在winZip的帮助下并将这些.class文件添加到war文件中。但问题是通过tomcat部署war文件后它没有显示任何更改。请让我知道我是否遵循了正确的流程。如果没有,请告诉我附加的确切方法.classfiles 到 war 文件。
I have one Example.war file, which dont have the src code of that war file.but i wanted to change some thing to the example.war file. so i created new page (.java file) and compiled the page through ant..it was build successfully.now i want to append the new page(.class file) to the Example.war.I just opened the example.war file with the help of winZip and added those .classfiles to the war file.but the thing is it doesnt showing any changes after deploying the war file through tomcat.please let me know whether i followed the correct process r not.If not kindly tell me the exact way of appending the .classfiles to the war file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用 WinZip。嗯,可以,但是每次更改 .war 中的 .class 文件集时,您都需要更新一个清单文件。
与其手动执行,最简单的方法是使用 JDK 附带的 jar 命令。
解压war(使用任何工具,但jar可以让你这样做),将.class文件放入lib目录中,然后使用jar工具重新打包war文件。
此页面展示了如何从蚂蚁内。
基本上,
You cannot use WinZip. Well, you can, but there's a manifest file you need to update, every time you change the set of .class files in the .war.
Rather than do it manually, the simple way to do it is to use the jar command that comes with the JDK.
Unpack the war (with any tool, but jar will let you do it), place your .class file into the lib directory, then repack the war file with the jar tool.
This page shows how to create a war from within ant.
basically,
您问题的第一个答案是“是的,您可以将类文件添加到 war 文件中”。当你说新的“页面”时,你的意思是新的servlet(我假设你是这样,因为你说它是一个Java类而不是一个JSP文件)?
如果您想将新的类文件编译到现有的 war 中,您将采取以下步骤:
然而,此时您还没有告诉 Web 应用程序您的新类文件(如果它是 servlet)。您需要执行的最后一步是编辑 WEB-INF 中的 web.xml 文件,以将 servlet 映射到路径。请参阅本文了解示例。
您可以查看有关整个过程的更多详细信息 此处。
最后,您可能必须清除应用程序服务器的缓存并重新启动它。如果您使用 Tomcat,最简单的方法是删除“work”目录中的所有内容并重新启动应用程序服务器。
The first answer to your question is "Yes, you can add class files to a war file". When you say new "page", do you mean new servlet (I assume you do, since you said it was a Java class and not a JSP file)?
If you wanted to compile a new class file into an existing war, you would take the following steps:
However, at this point you haven't told the web application about your new class file (if it is a servlet). The final step you will need to take is to edit the web.xml file in WEB-INF to map your servlet to a path. See this article for an example.
You can see some more details about this whole process here.
Finally, you may have to clean out the cache for your application server and restart it. if you are using Tomcat, the easiest way is to delete everything in the "work" directory and restart the application server.