我在哪里将axis2.xml放置在带有Soap Client的jar读取的位置? [英] Where do I place axis2.xml to be read by a jar with a soap client?

查看:140
本文介绍了我在哪里将axis2.xml放置在带有Soap Client的jar读取的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jar文件中有一个Java控制台应用程序.它通过 axis2 来调用肥皂服务.我正在使用此博客作为例子.我要添加的确切配置项如下:

<parameter name="Proxy">
    <Configuration>
             <ProxyHost>localhost</ProxyHost>
             <ProxyPort>8888</ProxyPort>
    </Configuration>
</parameter>

我尝试将其放在jar根目录中的axis2.xml文件中.我还编辑了C:\Program Files\Apache Software Foundation\axis2-1.5.4\conf\axis2.xml.

我的AXIS2_HOME设置正确:

set AXIS2_HOME
AXIS2_HOME=c:\Program Files\Apache Software Foundation\axis2-1.5.4

我确认流量肯定是通过 WireShark 直接发送到服务器的.

解决方案

您遇到了这个问题,因为JRE无法找到配置文件.

是的,应将配置文件放置在jar文件外部,因为程序无法读取jar文件(已压缩)内部的配置文件.

这里的问题是您必须正确地将程序指向配置文件.

相对文件路径是从Java Runtime Environment的启动位置开始计算的. (我们应该使用相对文件路径,因为我们要避免使用绝对文件路径,因为不是每个人都具有相同的系统环境,因此绝对文件路径将无法在不同的环境中工作)

在这种情况下,如果不确定JRE从何处开始,从而使您无法计算相对文件路径,则可以执行以下操作:

File file = new File("");
System.out.println(file.getAbsolutePath());

这将帮助您找出从何处开始JRE.您应该知道,相对文件路径是从JRE的起始目录计算得出的.

对于axis2,工作目录(JRE的起始目录)应为Apache Tomcat的bin文件夹,而对于您的程序,则取决于您对JRE的调用从何处启动程序./p>

我建议您将配置文件放置在易于访问的位置. 假设您要使用AXIS2_HOME,并将配置文件放置在AXIS2_HOME目录中,则可以在jar程序中执行以下操作以找到您的配置文件:

String value = System.getenv("AXIS2_HOME");    // gets the AXIS2_HOME environment variable
File file = new File(value+"/"+axis2.xml);

我想您会明白我在说什么.希望对您有所帮助! (:

I have a java console application inside of a jar file. It makes calls to a soap service via axis2. I am using this blog as the example. The exact configuration items I am adding are as follows:

<parameter name="Proxy">
    <Configuration>
             <ProxyHost>localhost</ProxyHost>
             <ProxyPort>8888</ProxyPort>
    </Configuration>
</parameter>

I tried putting that in an axis2.xml file in the root of my jar. I also edited C:\Program Files\Apache Software Foundation\axis2-1.5.4\conf\axis2.xml.

My AXIS2_HOME is set correctly:

set AXIS2_HOME
AXIS2_HOME=c:\Program Files\Apache Software Foundation\axis2-1.5.4

I verified the traffic is definitely being sent directly to the server via WireShark.

解决方案

You are having this problem because JRE is unable to find the configuration file.

Yes, the configuration file should be placed outside the jar file because a program cannot read the configuration file inside a jar file (which is compressed).

The problem here is that you have to point your program to the configuration file correctly.

Relative filepaths are calculated from where the Java Runtime Environment was started. (We should use relative filepaths because we want to avoid using absolute filepaths since not everyone will have the same system environment and thus absolute filepaths will not work in a different environment)

In this case, if you are unsure where your JRE is started from, making you unable to calculate your relative filepath, you can do:

File file = new File("");
System.out.println(file.getAbsolutePath());

This will help you find out where your JRE is started from. You should know that relative file paths are calculated from the directory where your JRE is started from.

For axis2, the working directory(where JRE is started from) should be the bin folder of your Apache Tomcat, while for your program, it will depend on where you made the call to the JRE to start the program from.

I would advise you to place your configuration file in a place where is easily accessible. Say if you wanted to use AXIS2_HOME, and you place your configuration file in the AXIS2_HOME directory, you can do the following inside your jar program to find your configuration file:

String value = System.getenv("AXIS2_HOME");    // gets the AXIS2_HOME environment variable
File file = new File(value+"/"+axis2.xml);

I think you get the gist of what I am saying. Hope that helps! (:

这篇关于我在哪里将axis2.xml放置在带有Soap Client的jar读取的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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