0

ANT タスクを使用して Java クラスをコンパイルし、次を使用して .h ファイルを生成しています。

Windows 7 の javah [バージョン "1.7.0_55"]

以下は私のbuild.xmlからのコードスニペットです

...
<property name="build.dir"        value="./main/test_target"/>
<property name="classes.dir"      value="${build.dir}/classes"/>
<property name="external.lib.dir" value="./externalJars"/>  <!-- contains spring-context-3.0.3.jar file --> 
<property name="jni.output.dir"   value="${build.dir}/jniHeaders"/>
..
...
<target name="compile-header" depends="build">

    <exec executable="javah">
        <arg line="-classpath ${classes.dir};${external.lib.dir} -o ${jni.output.dir}/MyNativeImpl.h -verbose -force examples.MyNativeImpl"/>
    </exec>
</target>

...
..

しかし、.h ファイルを生成できず、次のエラーが発生します。

Error: Class org.springframework.context.MessageSource could not be found.

「spring-context-3.0.3.jar」をexternalJars dir => ${external.lib.dir}に追加したにもかかわらず

私の Java ファイル MyNativeImpl.java は、パッケージ "import org.springframework.context.MessageSource; " を使用します。Java ファイルのコンパイルは、${external.lib.dir} と MyNativeImpl.class も ${classes.dir} の下に生成されます。

何が間違っているのかわからない!!

SSの検索にほぼ1日を費やしましたが、特定の解決策を見つけることができました. ${external.lib.dir}の下でアプリを完全にコンパイルするために、Spring フレームワークからこのような依存 jar がたくさんあるため、JAVAH が .jar ファイル内のクラスを見つけることができるように、これを解決する方法を知りたいと思いました!!

Surprisingly I have a work-around which is:

1. unzip the contents of pring-context-3.0.3.jar to CLASSES DIR  ${classes.dir}
2. now my ${classes.dir} has following contents
   a. examples/MyNativeImpl.class
   b. org/springframework/context/MessageSource.class  ( and other classes )

3. Now JAVAH doesn't complain and generate my MyNativeImpl.h

しかし、spring-context-3.0.3.jar を使用すると、同じ MessageSource.class が見つからない理由がわかりました??

私が欠けているものはありますか、それともこれが唯一の方法です:-(どんな助けも大歓迎です。

前もって感謝します

よろしく、 Vivek

4

1 に答える 1

1

クラスパスで jar を指定するときは、各 jar をリストする必要があります。jar を含むディレクトリは十分ではなく、クラスに対してのみ機能し、回避策が機能する理由を説明しています。

私は次のようなものを提案します:

<path id="javah.path">
  <pathelement location="${classes.dir}"/>
  <fileset dir="${external.lib.dir}" includes="*.jar"/>
</path>

<pathconvert property="javah.classpath" refid="javah.path"/>

<exec executable="javah">
  <arg line="-classpath ${javah.classpath} -o ... />
</exec>

PS

于 2015-01-09T08:35:11.743 に答える