javac“无源文件"使用-h选项时 [英] javac "no source files" when using -h option

查看:684
本文介绍了javac“无源文件"使用-h选项时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JNI和JDK9.我有一个类NativeTest.java,看起来像这样:

I'm trying to experiment with using the JNI and JDK 9. I have a class NativeTest.java that looks like this:

public class NativeTest {

    static {
        System.loadLibrary("hello");
    }

    private native void sayHello();

    public static void main(String[] args) {
        new NativeTest().sayHello();
    }
}

我编译该类,然后使用javah NativeTest生成头文件.

I compile the class, then use javah NativeTest to generate the header file.

发布javah时,我收到此警告:

Upon issuing javah, I get this warning:

Warning: The javah tool is planned to be removed in the next major
JDK release. The tool has been superseded by the '-h' option added
to javac in JDK 8. Users are recommended to migrate to using the
javac '-h' option; see the javac man page for more information.

我知道下一个主要的JDK版本还需要很长时间,但是我认为我现在将开始习惯这个新选项.

I know it'll be quite a while before the next major JDK release, but I figured I'd start getting used to this new option now.

因此,尝试使用javac -h NativeTest.java(以及其他变体,例如NativeTestNativeTest.class等)时,我总是收到此错误:

So upon trying javac -h NativeTest.java (and other variations like NativeTest, NativeTest.class, etc.) I keep getting this error:

javac: no source files

我无法在线找到任何帮助,可能是因为此功能是相对较新的,并且在手册页中找不到关于此新-h选项的任何信息.

I haven't been able to find any help online, probably because this feature is relatively new, and I can't find anything about this new -h option in the man page.

还有其他人尝试吗?我想念什么?

Anyone else try this yet? What am I missing?

推荐答案

我发现的解决方案是我没有指定javac放置头文件的目录.

The solution I discovered was that I was not specifying the directory where javac should place the header files.

执行javac -h . NativeTest.java成功.

这篇关于javac“无源文件"使用-h选项时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆