gpt4 book ai didi

java - 在 Linux 上从 eclipse 运行 ant build 时出错。无法从 ant 调用 wsimport

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:02 28 4
gpt4 key购买 nike

最近我切换到 Linux Mint 15,我在使用 Eclipse 和 ant 时遇到了问题。这是导致问题的一段 Ant 脚本:

                <exec osfamily="unix" executable="wsimport">
<arg line="${prefix}/${jaxb.resources}/${jaxb.schema@{i}} -s ${prefix}/${jaxb.src} -p ${jaxb.package@{i}} -wsdllocation ${jaxb.schema@{i}} -b ${prefix}/jaxb-bindings.xml -Xdebug -verbose -Xnocompile" />
</exec>

但是,在构建期间,在 eclipse 中使用 ant,出现以下错误:

Execute failed: java.io.IOException: Cannot run program "wsimport": error=2, No such file or directory

我知道这是因为 Eclipse 无法找到作为 JDK 一部分的 wsimport 工具。但是,如果我在终端内运行这个 ant 脚本,一切都会正确通过。我的 .bashrc 将 PATH 变量设置为 jdk/bin 文件夹,并且可以通过终端访问 wsimport。 Eclipse 使用安装在我机器上的 ant 版本(不是嵌入式版本),项目是使用 JDK 编译器(不是嵌入式版本)构建的。我使用 Oracle 的 JDK 1.7.0_45 64 位。

提前致谢。

编辑:

我在/usr/lib/jvm/jdk 中手动安装了我的 JDK(不是通过包安装程序)。使用 update-alternatives 配置它并在我的用户的 .bashrc 中设置 JAVA_HOME 和 PATH 变量。就像我说的,ant 脚本在终端上运行,但在 Eclipse 上运行(在 ant 窗口上),也许 eclipse 不知道 .bashrc 中的 PATH 变量...

最佳答案

(这是一个老问题,但也许这会在将来帮助其他人。)您可以使用 Ant 任务运行 wsgen 和 wsimport。我不熟悉你所有的变量,所以我的例子只是做它自己的事情。它需要变量:

  • metro.home - webservices-tools.jar 的位置
  • build.classpath - 依赖的 jar 文件的类路径
  • build.classes - @WebService 类的类路径
  • basedir - 您编写 wsgen 和 wsimport 文件的位置

这是例子。

<!-- setup Metro tooltime classpath -->
<path id="tool.cp">
<path refid="runtime.cp"/>
<pathelement location="${metro.home}/webservices-tools.jar"/>
</path>

<!--
Setup Wsimport ant task. You would use this task in WSDL to Java case
to compile a WSDL and generate Java classes.
-->
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath refid="tool.cp"/>
</taskdef>

<!--
Setup Wsgen ant task. You would use this task in Java to WSDL case to
generate a WSDL or wrapper classes.
-->
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
<classpath refid="tool.cp"/>
<classpath refid="build.classpath"/>
</taskdef>

<target name="wsimport">
<wsgen sei="com.company.app.ws.Authorize"
classpath="${build.classes}"
sourcedestdir="${basedir}/wsgen/src"
destdir="${basedir}/wsgen/classes"
keep="true" verbose="true" genwsdl="true" resourcedestdir="wsgen">
<classpath refid="build.classpath"/>
</wsgen>
<wsimport verbose="true" keep="true"
destdir="${basedir}/wsimport/classes"
sourcedestdir="${basedir}/wsimport/src"
wsdl="${basedir}/wsgen/AuthorizeService.wsdl"
/>
</target>

注意:当我从在 RedHat 上运行的 Jenkins 启动 Ant 脚本时,这也适用于我。

注意:如果您尝试在 Eclipse 中使用外部工具运行 Ant,如果您选择 JRE,例如“jre7”代表外部工具配置中的 JRE;更好地配置和使用 JDK,例如“jdk1.7.0_80”。此外,将“tools.jar”添加为外部工具配置中的附加类路径条目。

关于java - 在 Linux 上从 eclipse 运行 ant build 时出错。无法从 ant 调用 wsimport,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19979797/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com