不用eclipse通过ant生成webservice
Generate webservice via ant without eclipse
我正在尝试使用 ant 从现有代码生成 Web 服务到 war 文件。 Eclipse 生成一个完整的 ant 构建文件 (axis_bujava.xml),它可以工作(但 undeploy.wsdd 并非一直生成,我不知道为什么),但前提是我从 eclipse 运行 它。
我想要一个独立的脚本来生成我的网络服务(并将其打包到 war 文件之后,但这不是问题 ^^)
我从 eclipse 插件文件夹中添加了一些 jar 到类路径并创建了任务 "wsgen" 但我没有得到 "null pointer exception".
我的axis_bujava.xml:
<?xml version="1.0"?>
<project default="main" basedir=".">
<echo message="pulling in property files"/>
<property file="axis_bujava.properties"/>
<path id="wsgenlib">
<fileset dir="${ant.library.dir}/org.eclipse.wst.command.env/" includes="ant-lib/anttasks.jar"/>
</path>
<taskdef name="wsgen"
classname="ws.ant.task.WebServiceGenerationAntTask"
classpath="${ant.library.dir}/org.eclipse.wst.command.env"
/>
<echo message="calling the web services generation ant task: axis_bujava"/>
<target name="main" >
<wsgen />
</target>
</project>
错误:
D:\Dev\S_Demo\ant\axis_bujava.xml:22: java.lang.NullPointerException
at org.eclipse.wst.command.internal.env.context.PersistentContext.(PersistentContext.java:31)
at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.(PersistentResourceContext.java:36)
at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.getInstance(PersistentResourceContext.java:27)
at org.eclipse.wst.command.internal.env.ant.AntController.(AntController.java:56)
at ws.ant.task.WebServiceGenerationAntTask.execute(WebServiceGenerationAntTask.java:31)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
正如我在评论中所说,我通过直接使用 Axis class 解决了这个问题(就像 eclipse 一样):
重要说明:使用的 Ant 版本:
Apache Ant(TM) version 1.9.2 compiled on July 8 2013
1、依赖项(最小列表,在执行时将它们添加到 ant classpath 中):
- axis.jar
- 轴-ant.jar
2、蚂蚁 build.xml :
从轴获取任务-ant.jar
<taskdef
resource="axis-tasks.properties"
/>
在目标中:
- 生成wsdl文件
注意:如果不起作用,请使用 org.apache.axis.wsdl.Java2WSDL,类似于下一点,两者都有一个“-h”选项来帮助
<axis-java2wsdl
output="WebContent/WEB-INF/NameOf.wsdl"
namespace="http://org.acme.com"
style="WRAPPED"
location="http://localhost/MyService/service/MyServiceImpl"
classname="com.acme.org.MyServiceImpl"
classpath="build/classes"
/>
- 生成deploy/undeploy.wsdd 文件
直接使用 "java" 因为,在我的例子中,来自 axis-ant 的 ant 任务不起作用。和执行任务,我有一些问题 java 任务(蚂蚁版本的原因)
<exec executable="java">
<arg value="-cp" />
<arg value="${path.dependencies}/*;build/classes" />
<arg value="org.apache.axis.wsdl.WSDL2Java" />
<arg value="-d"/>
<arg value="Application"/>
<arg value="-o"/>
<arg value="WebContent/WEB-INF/MyServiceImplService/"/>
<arg value="-p"/>
<arg value="com.acme.org"/>
<arg value="-c"/>
<arg value="com.acme.org.MyServiceImpl"/>
<arg value="-s"/>
<arg value="WebContent/WEB-INF/NameOf.wsdl"/>
</exec>
生成服务器-config.wsdd
<exec executable="java">
<arg value="-cp" />
<arg value="${path.dependencies}/*" />
<arg value="org.apache.axis.utils.Admin" />
<arg value="server"/>
<arg value="WebContent/WEB-INF/MyServiceImplService/com.acme.org/deploy.wsdd"/>
</exec>
<move file="server-config.wsdd" tofile="WebContent/WEB-INF/server-config.wsdd"/>
清理生成的 jar 文件
<delete>
<fileset dir="WebContent/WEB-INF/MyServiceImplService/com.acme.org/" includes="*.java" />
</delete>
我正在尝试使用 ant 从现有代码生成 Web 服务到 war 文件。 Eclipse 生成一个完整的 ant 构建文件 (axis_bujava.xml),它可以工作(但 undeploy.wsdd 并非一直生成,我不知道为什么),但前提是我从 eclipse 运行 它。
我想要一个独立的脚本来生成我的网络服务(并将其打包到 war 文件之后,但这不是问题 ^^)
我从 eclipse 插件文件夹中添加了一些 jar 到类路径并创建了任务 "wsgen" 但我没有得到 "null pointer exception".
我的axis_bujava.xml:
<?xml version="1.0"?>
<project default="main" basedir=".">
<echo message="pulling in property files"/>
<property file="axis_bujava.properties"/>
<path id="wsgenlib">
<fileset dir="${ant.library.dir}/org.eclipse.wst.command.env/" includes="ant-lib/anttasks.jar"/>
</path>
<taskdef name="wsgen"
classname="ws.ant.task.WebServiceGenerationAntTask"
classpath="${ant.library.dir}/org.eclipse.wst.command.env"
/>
<echo message="calling the web services generation ant task: axis_bujava"/>
<target name="main" >
<wsgen />
</target>
</project>
错误:
D:\Dev\S_Demo\ant\axis_bujava.xml:22: java.lang.NullPointerException at org.eclipse.wst.command.internal.env.context.PersistentContext.(PersistentContext.java:31) at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.(PersistentResourceContext.java:36) at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.getInstance(PersistentResourceContext.java:27) at org.eclipse.wst.command.internal.env.ant.AntController.(AntController.java:56) at ws.ant.task.WebServiceGenerationAntTask.execute(WebServiceGenerationAntTask.java:31) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) at org.apache.tools.ant.Project.executeTarget(Project.java:1364) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1248) at org.apache.tools.ant.Main.runBuild(Main.java:851) at org.apache.tools.ant.Main.startAnt(Main.java:235) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
正如我在评论中所说,我通过直接使用 Axis class 解决了这个问题(就像 eclipse 一样):
重要说明:使用的 Ant 版本:
Apache Ant(TM) version 1.9.2 compiled on July 8 2013
1、依赖项(最小列表,在执行时将它们添加到 ant classpath 中):
- axis.jar
- 轴-ant.jar
2、蚂蚁 build.xml :
从轴获取任务-ant.jar
<taskdef
resource="axis-tasks.properties"
/>
在目标中:
- 生成wsdl文件
注意:如果不起作用,请使用 org.apache.axis.wsdl.Java2WSDL,类似于下一点,两者都有一个“-h”选项来帮助
<axis-java2wsdl
output="WebContent/WEB-INF/NameOf.wsdl"
namespace="http://org.acme.com"
style="WRAPPED"
location="http://localhost/MyService/service/MyServiceImpl"
classname="com.acme.org.MyServiceImpl"
classpath="build/classes"
/>
- 生成deploy/undeploy.wsdd 文件
直接使用 "java" 因为,在我的例子中,来自 axis-ant 的 ant 任务不起作用。和执行任务,我有一些问题 java 任务(蚂蚁版本的原因)
<exec executable="java">
<arg value="-cp" />
<arg value="${path.dependencies}/*;build/classes" />
<arg value="org.apache.axis.wsdl.WSDL2Java" />
<arg value="-d"/>
<arg value="Application"/>
<arg value="-o"/>
<arg value="WebContent/WEB-INF/MyServiceImplService/"/>
<arg value="-p"/>
<arg value="com.acme.org"/>
<arg value="-c"/>
<arg value="com.acme.org.MyServiceImpl"/>
<arg value="-s"/>
<arg value="WebContent/WEB-INF/NameOf.wsdl"/>
</exec>
生成服务器-config.wsdd
<exec executable="java"> <arg value="-cp" /> <arg value="${path.dependencies}/*" /> <arg value="org.apache.axis.utils.Admin" /> <arg value="server"/> <arg value="WebContent/WEB-INF/MyServiceImplService/com.acme.org/deploy.wsdd"/> </exec> <move file="server-config.wsdd" tofile="WebContent/WEB-INF/server-config.wsdd"/>
清理生成的 jar 文件
<delete> <fileset dir="WebContent/WEB-INF/MyServiceImplService/com.acme.org/" includes="*.java" /> </delete>