Where do I place axis2.xml to be read by a jar with a soap client?

左心房为你撑大大i 提交于 2019-12-23 15:44:47

问题


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.


回答1:


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! (:



来源:https://stackoverflow.com/questions/6284862/where-do-i-place-axis2-xml-to-be-read-by-a-jar-with-a-soap-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!