开发者

Is it possible to add .class(java) files separately to the existing .war file?

I have one Example.war file, which dont have the s开发者_C百科rc 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.


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,

<target name="war" depends="compile"> 
  <war destfile="dist/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
    <fileset dir="WebContent"/> 
    <lib dir="WebContent/WEB-INF/lib"/> 
    <classes dir="build/classes"/> 
  </war> 
</target>


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:

  1. Make sure the java version you are compiling it with using ANT is the same as the java version your application server is using (the one hosting the WAR file).
  2. Compile the .class file in ANT, like you are doing.
  3. You can use any zip editor (WinZip -- although I prefer WinRAR) to open up the war file and put the .class file in the WEB-INF/classes folder.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜