java Web 服务作为 JAR 文件,还是另一个 WAR 中的 WAR?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6017374/
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
Web service as a JAR file, or WAR inside another WAR?
提问by Spring
I have a SOAP web service running on Tomcat 6 (using Spring Web Services, Java)
我有一个在 Tomcat 6 上运行的 SOAP Web 服务(使用 Spring Web 服务、Java)
Now I want to merge this webservice into another big web application (uses Spring, Java and not a web service) and use the web service as kinda plugin for the main web app. I mean when I run my main app my web service will also start to run. And they will use the same resources.
现在我想将此 Web 服务合并到另一个大型 Web 应用程序(使用 Spring、Java 而不是 Web 服务)并将 Web 服务用作主 Web 应用程序的插件。我的意思是当我运行我的主应用程序时,我的网络服务也将开始运行。他们将使用相同的资源。
The main web app already has several plugins which are JAR files in its WEB-INF/LIB folder. But my web service is a WAR file so can I use a web application (WAR file) inside another web applications WEB-INF/LIB folder?
主 Web 应用程序已经有几个插件,它们是其 WEB-INF/LIB 文件夹中的 JAR 文件。但是我的 Web 服务是一个 WAR 文件,所以我可以在另一个 Web 应用程序 WEB-INF/LIB 文件夹中使用一个 Web 应用程序(WAR 文件)吗?
If I can not do that is that possible to remove the WEB-INF folder of my web service and make my web service a JAR fileand put it under my main apps WEB-INf/LIB folder? I am not sure that I can serve a web service as a JAR file.
如果我不能这样做,是否可以删除我的 Web 服务的 WEB-INF 文件夹并使我的 Web 服务成为 JAR 文件并将其放在我的主要应用程序 WEB-INf/LIB 文件夹下?我不确定是否可以将 Web 服务作为 JAR 文件提供。
Which approach do you think is better or do you have other suggestions?
您认为哪种方法更好,或者您有其他建议?
Thanks
谢谢
采纳答案by Johan Sj?berg
I would recommend that you make a JAR out of your webservice and put that in the lib folder. The good thing about java is that it doesn't matter where your code is located as long as you load it right.
我建议您从您的网络服务中制作一个 JAR 并将其放在 lib 文件夹中。Java 的好处在于,只要您正确加载代码,您的代码位于何处并不重要。
I don't think you can have WAR inside WAR. You can however merge two WAR projects into one (which can be performed e.g., by the maven build system). Still, merging WARs is a copy-paste-overwrite operation which leaves alot to desire.
我不认为你可以在 WAR 中包含 WAR。但是,您可以将两个 WAR 项目合并为一个(例如,可以由 maven 构建系统执行)。尽管如此,合并 WAR 是一种复制-粘贴-覆盖操作,这让很多人望而却步。
回答by Jigar Joshi
I'd copied the relevant servlet & some configuration into the main web-app. also dedicated few packages to webservices classes and added required dependencies.
我已将相关的 servlet 和一些配置复制到主 Web 应用程序中。还专门为 webservices 类提供了一些包,并添加了所需的依赖项。