从ant执行sqlplus无法找到DYLD_LIBRARY_PATH

时间:2018-02-10 22:43:10

标签: ant sqlplus

我尝试使用sqlplus的execute标记从Apache Ant中运行SQL脚本。

    <exec dir="src/sql" executable="sqlplus" failonerror="true" output="src/sql/test.sql.err">
        <arg value="${db.login}"/>
        <arg value="@test.sql"/>
    </exec>

Sqlplus使用相同的参数从命令行工作。

Ant然而返回:

dyld: Library not loaded: /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib

对于我设置的命令行:

export DYLD_LIBRARY_PATH=/Applications/instantclient_11_2/

我需要采取与Ant相同的操作来查找库吗?

2 个答案:

答案 0 :(得分:2)

一种选择是尝试SQLcl。  它是sqldev的sql脚本引擎,它是sqlplus,还有更多 http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/sqlcl-index-2994757.html

好处是,它没有自包含的库,并使用JDBC Thin驱动程序进行数据库连接。

这是您的ANT示例..

<project name="sqlcl" basedir=".">
  <property name="db.login" value="klrice/klrice"/>
  <target name="sqlcl">

  <exec dir="." executable="/Users/klrice/Downloads/sqlcl/bin/sql"
        failonerror="true"
        output="sql/test.sql.err">
        <arg value="${db.login}"/>
        <arg value="@sql/dual.sql"/>
    </exec>
</target>
</project>

然后跑......

$ ant sqlcl
Buildfile: /Users/klrice/build.xml

sqlcl:

BUILD SUCCESSFUL
Total time: 3 seconds
587211042:~ klrice$ more sql/test.sql.err

SQLcl: Release 17.4.0 Production on Wed Mar 07 21:59:54 2018

Copyright (c) 1982, 2018, Oracle.  All rights reserved.

Last Successful login time: Wed Mar 07 2018 22:00:08 -05:00

Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production

login.sql found in the CWD. DB access is restricted for login.sql.
Adjust the SQLPATH to include the path to enable full functionality.

         1
----------
         1


Disconnected from Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production

答案 1 :(得分:0)

使用解决方案@ kris-rice建议,这是我的实现,包括检查错误......

<!-- =================================================================== -->
<!-- load plsql tox -->
<!-- =================================================================== -->
<target name="compile.plsql.tox" description="compile plsql for tox">
    <echo message="compile.plsql.tox --------------------"/>
    <mkdir dir="tmp/log"/>
    <exec dir="src/sql" executable="sql" failonerror="true" output="src/sql/tox.all.sql.err">
        <arg value="${db.login.tox}"/>
        <arg value="@tox.all.sql"/>
    </exec>
    <echo message="looking for plsql errors -------------------"/>
    <exec dir="src/sql" executable="grep" failonerror="false" resultproperty="found">
        <arg value="LINE/COL ERROR"/>
        <arg value="tox.all.sql.err"/>
    </exec>
    <fail message="plsql compile errors">
        <condition>
            <equals arg1="${found}" arg2="0"/>
        </condition>
    </fail>
    <echo message="looking for line item errors ---------------"/>
    <exec dir="src/sql" executable="grep" failonerror="false" resultproperty="found">
        <arg value="ERROR at"/>
        <arg value="tox.all.sql.err"/>
    </exec>
    <fail message="sql compile errors">
        <condition>
            <equals arg1="${found}" arg2="0"/>
        </condition>
    </fail>
    <echo message="compile.plsql.tox --------------------"/>
</target>
<!-- =================================================================== -->