Axis2 + Tomcat:Web服务工作目录 [英] Axis2 + Tomcat: Web service working directory

查看:66
本文介绍了Axis2 + Tomcat:Web服务工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个Axis2 Web服务(称为"ReleaseService"),该服务需要一个属性文件才能正常工作.我已经将axis2部署到RHEL6上的Tomcat7中,并且具有这样的结构:

So I have an Axis2 web service (called "ReleaseService"), which requires a properties file to work correctly. I've deployed axis2 into Tomcat7 on RHEL6 and have a structure like this:

tomcat/webapps/axis2
+ axis2-web, META-INF, org
+ WEB-INF
+ + classes, conf, lib, modules
+ + services
+ + + ReleaseService
+ + + + com, lib, META-INF

关于Java,我希望工作目录为 tomcat/webapps/axis2/WEB-INF/services/ReleaseService ,因为它包含一个lib文件夹和我的二进制文件的根文件夹.

Thinking about Java, I would expect the working directory to be tomcat/webapps/axis2/WEB-INF/services/ReleaseService, because it contains a lib folder and the root folder for my binaries.

所以我将属性文件放在其中,并尝试通过

So I put my properties file in there and tried to access it via

File configFile = new File("releaseservice.properties");

显然不起作用.我已经找了几个小时,但找不到帖子或文档摘要,它告诉我工作目录在哪里.我发现了,但它是系统属性对我而言,这是没有选择的,因为我想保持部署简单.

which apparently doesn't work. I've looked for hours but couldn't find a post or documentation snippet, which tells me where the working directory is. I found this, but a system property is no option for me, because I want to keep the deployment simple.

发现,工作目录是我的 tomcat/bin 文件夹,它是Tomcat Java进程的根目录.

Found out, that the working directory is my tomcat/bin folder, which is the root of the Tomcat Java process.

奖励问题:如何在我的Web服务中找到我的服务目录?Axis2是否提供任何帮助程序来找出服务的文件夹?

Bonus question: How can I find out my service directory inside my web service? Does Axis2 provide any helpers to find out which is the folder for the service?

推荐答案

不建议对部署在Java EE容器中的应用程序代码中的当前工作目录进行假设.另外,您假设部署WAR时, releaseservice.properties 将作为文件存在,即容器会爆炸WAR.对于Tomcat来说确实如此,但在其他服务器上可能并非如此.

Making assumptions about the current working directory in application code deployed in a Java EE container is not recommended. In addition, you are making the assumption that when the WAR is deployed, releaseservice.properties will exist as a file, i.e. that the container explodes the WAR. This is true for Tomcat, but may not be the case on other servers.

Axis2为每个已部署的服务创建一个不同的类加载器.这意味着您可以通过将其查找为资源来访问其属性文件:

Axis2 creates a distinct class loader for every deployed service. This means that you can access your property file by looking it up as a resource:

MyService.class.getResourceAsStream("/releaseservice.properties")

用实现您的服务的实际类或从 WEB-INF/services/ReleaseService 加载的任何其他类替换 MyService .

Replace MyService with the actual class implementing your service, or any other class loaded from WEB-INF/services/ReleaseService.

这篇关于Axis2 + Tomcat:Web服务工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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