我正在使用 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} 下生成
不知道我做错了什么!!
几乎花了 1 天时间在 SS 上搜索,但可以找到特定的解决方案。我有许多来自 spring 框架的此类依赖 jar,可以在${external.lib.dir}下完全编译我的应用程序,因此想知道如何解决这个问题,以便 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 ?
是否有我遗漏的东西或者这是唯一的方法:-(非常感谢任何帮助。
提前致谢
问候, 维维克