簡體   English   中英

在Linux上從Eclipse運行ant build時出錯。 無法從ant調用wsimport

[英]Error while running ant build from eclipse on Linux. Cannot call wsimport from ant

最近,我切換到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選擇JRE時可能會遇到問題,例如“ jre7”。 更好地配置和使用JDK,例如“ jdk1.7.0_80”。 另外,在“外部工具配置”中,將“ tools.jar”添加為附加的類路徑條目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM