简体   繁体   English

使用ant使JAX-WS客户端在Weblogic 9.2上运行

[英]Getting JAX-WS client work on Weblogic 9.2 with ant

I've recently had lots of issues trying to deploy a JAX-WS web servcie client on Weblogic 9.2. 我最近在尝试在Weblogic 9.2上部署JAX-WS Web服务客户端时遇到了很多问题。 It turns out there is no straightforward guide on how to achieve this, so I decided to put together this short wiki entry hoping it might be useful for others. 事实证明,没有直接的指导如何实现这一点,所以我决定将这个简短的wiki条目放在一起,希望它可能对其他人有用。

Firstly, Weblogic 9.2 does not support web servcies using JAX-WS in general. 首先,Weblogic 9.2一般不支持使用JAX-WS的Web服务。 It comes with old versions of XML-related java libraries that are incompatible with the latest JAX-WS (similar issues occur with Axis2, only Axis1 seems to be working flawlessly with Weblogic 9.x but that's a very old and unsupported library). 它附带了与最新的JAX-WS不兼容的旧版XML相关的Java库(Axis2也出现了类似的问题,只有Axis1似乎与Weblogic 9.x完美配合,但这是一个非常古老且不受支持的库)。

So, in order to get it working, some hacking is required. 因此,为了使其正常工作,需要进行一些黑客攻击。 This is how I did it (note that we're using ant in our legacy corporate project, you probably should be using maven which should eliminate 50% of those steps below): 这就是我做的方式(注意我们在我们的遗留公司项目中使用了ant,你可能应该使用maven,它应该消除以下50%的步骤):

1.Download the most recent JAX-WS distribution from https://jax-ws.dev.java.net/ (The exact version I got was JAXWS2.2-20091203.zip) 1.从https://jax-ws.dev.java.net/下载最新的JAX-WS发行版(我得到的确切版本是JAXWS2.2-20091203.zip)

2.Place the JAX-WS jars with the dependencies in a separate folder like lib/webservices . 2.将JAX-WS jar与依赖项放在一个单独的文件夹中,如lib / webservices

3.Create a patternset in ant to reference those jars: 3.在ant中创建一个模式集来引用这些jar:

<?xml version="1.0"?>
<patternset id="jaxws.classpath">
<include name="webservices/jsr173_api.jar" />  
<include name="webservices/jsr181-api.jar" />       
<include name="webservices/jaxb-api.jar" />
<include name="webservices/jaxb-impl.jar" />
<include name="webservices/jaxb-xjc.jar" /> 
<include name="webservices/jaxws-tools.jar" />
<include name="webservices/jaxws-rt.jar" />       
<include name="webservices/jaxws-api.jar" />
<include name="webservices/policy.jar" />
<include name="webservices/woodstox.jar" />   
<include name="webservices/streambuffer.jar" />       
<include name="webservices/stax-ex.jar" />
<include name="webservices/saaj-api.jar" />
<include name="webservices/saaj-impl.jar" />
<include name="webservices/gmbal-api-only.jar" />   
</patternset>

4.Include the patternset in your WAR-related goal. 4.在您的WAR相关目标中包含模式集。 This could look something like: 这看起来像是这样的:

<?xml version="1.0"?>
<copy todir="${wardir.lib}" includeEmptyDirs="false" flatten="true">
<fileset dir="${libs}">
<!--lots of libs here, related to your project -->
<patternset refid="jaxws.classpath"/>
</fileset>
</copy>

(not the flatten="true" parameter - it's important as Weblogic 9.x is by default not smart enough to access jars located in a different lcoation than WEB-INF/lib inside your WAR file) (不是flatten =“true”参数 - 这很重要,因为Weblogic 9.x默认情况下不够智能,无法访问位于WAR文件中不同于WEB-INF / lib的lcoation中的jar)

5.In case of clashes, Weblogic uses its own jars by default. 5.如果发生冲突,Weblogic默认使用自己的jar。 We want it to use the JAX-WS jars from our application instead. 我们希望它使用我们应用程序中的JAX-WS jar。 This is achieved by preparing a weblogic-application.xml file and placing it in META-INF folder of the deplotyed EAR file. 这是通过准备weblogic-application.xml文件并将其放在deplotyed EAR文件的META-INF文件夹中来实现的。 It should look like this: 它应该如下所示:

<?xml version="1.0"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<prefer-application-packages>
    <package-name>javax.jws.*</package-name>
    <package-name>javax.xml.bind.*</package-name>
    <package-name>javax.xml.crypto.*</package-name>
    <package-name>javax.xml.registry.*</package-name>
    <package-name>javax.xml.rpc.*</package-name>
    <package-name>javax.xml.soap.*</package-name>
    <package-name>javax.xml.stream.*</package-name>
    <package-name>javax.xml.ws.*</package-name>
    <package-name>com.sun.xml.api.streaming.*</package-name>
</prefer-application-packages>
</weblogic-application>

6.Remember to place that weblogic-application.xml file in your EAR! 6.记得将weblogic-application.xml文件放在你的EAR中! The ant goal for that may look similar to: 蚂蚁的目标可能类似于:

<?xml version="1.0"?>
<target name="build-ear" depends="war, manifest">
    <delete dir="${dist}"/>
    <mkdir dir="${dist}"/>    
    <jar destfile="${warfile}" basedir="${wardir}"/>        
    <ear destfile="${earfile}" appxml="resources/${app.name}/application.xml">
        <fileset dir="${dist}" includes="${app.name}.war"/>
        <metainf dir="resources/META-INF"/>     
    </ear>
</target>

7.Also you need to tell weblogic to prefer your WEB-INF classes to those in distribution. 7.此外,您需要告诉weblogic更喜欢您的WEB-INF类和发布中的类。 You do that by placing the following lines in your WEB-INF/weblogic.xml file: 您可以通过在WEB-INF / weblogic.xml文件中放置以下行来完成此操作:

<?xml version="1.0"?>
<container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

8.And that's it for the weblogic-related configuration. 8.这就是与weblogic相关的配置。 Now only set up your JAX-WS goal. 现在只设置你的JAX-WS目标。 The one below is going to simply generate the web service stubs and classes based on a locally deployed WSDL file and place them in a folder in your app: 下面的内容将简单地基于本地部署的WSDL文件生成Web服务存根和类,并将它们放在应用程序的文件夹中:

<?xml version="1.0"?>
<target name="generate-jaxws-client">
        <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"> 
            <classpath path="classpath.main"/>
        </taskdef>          
        <wsimport 
             destdir="${src}"
             package="acme.somewhere.in.your.package.tree.webservices."
             keep="true" 
             wsdl="http://localhost:8088/mockWebService?WSDL">              
        </wsimport>
    </target>   

Remember about the keep="true" parameter. 请记住keep =“true”参数。 Without it, wsimport generates the classes and... deletes them, believe it or not! 没有它,wsimport会生成类并且......删除它们,信不信由你!

For mocking a web service I suggest using SOAPUI, an open source project. 对于模拟Web服务,我建议使用SOAPUI,一个开源项目。 Very easy to deploy, crucial for web servcies intergation testing. 非常易于部署,对于Web服务集成测试至关重要。

9.We're almost there. 我们快到了。 The final thing is to write a Java class for testing the web service, try to run it as a standalone app first (or as part of your unit tests) 最后是编写一个用于测试Web服务的Java类,尝试首先将其作为独立应用程序运行(或作为单元测试的一部分)

10.And then try to run the same code from withing Weblogic. 10.然后尝试使用Weblogic运行相同的代码。 It should work. 它应该工作。 It worked for me. 它对我有用。 After some 3 days of frustration. 经过3天的挫折。 And yes, I know I should've put 9 and 10 under a single bullet-point, but the title "10 steps to deploy a JAX-WS web service under Web logic 9.2 using ant" sounds just so much better. 是的,我知道我应该将9和10放在一个子弹点下,但标题“使用ant在Web逻辑9.2下部署JAX-WS Web服务的10个步骤”听起来好多了。

Please, edit this post and improve it if you find something missing! 如果您发现缺少某些内容,请编辑此帖并进行改进!

这不是一个问题,而是一个指南,所以我自己回答它只是为了将其标记为已完成。

Another way of dealing with web services on Weblogic 9.2 is using Apache CXF. 在Weblogic 9.2上处理Web服务的另一种方法是使用Apache CXF。 This particularly well integrates with Spring as each web service is exposed as a bean and the actual classes don't even need to know that they are web services, it's all configuration driven. 这特别好地与Spring集成,因为每个Web服务都作为bean公开,实际的类甚至不需要知道它们是Web服务,它都是由配置驱动的。

A great guide about setting up Apache CXF on Weblogic can be found here: http://wheelersoftware.com/articles/spring-cxf-web-services.html 有关在Weblogic上设置Apache CXF的精彩指南,请访问: http//wheelersoftware.com/articles/spring-cxf-web-services.html

This works on Weblogic 9.2 as well and if you need to expose web services, not just connect to existing ones, this is by far better approach than using plain JAXWS (which is used by CXF anyway). 这也适用于Weblogic 9.2,如果您需要公开Web服务,而不仅仅是连接到现有服务,这比使用普通JAXWS(无论如何都使用CXF)要好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM