首页 文章

从ant执行sqlplus无法找到DYLD_LIBRARY_PATH

提问于
浏览
0

我正在尝试使用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

    一种选择是尝试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
    
  • 2

    使用@ 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>
    <!-- =================================================================== -->
    

相关问题