Javah工具错误:无法找到hellojni的类文件 [英] Javah tool error: Could not find class file for hellojni

查看:1332
本文介绍了Javah工具错误:无法找到hellojni的类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows 7操作系统上从命令行使用javah工具创建头文件,但我一直都失败了。

I am trying to create a header file using javah tool from command line on windows 7 OS but i am failing all the time.

我已经按照不同的方式,甚至从oracle阅读了javah工具的文档,但是他们没有帮助克服这个问题。

I have followed different ways and even read the documentation of javah tool from oracle but they didn't help to overcome with this problem.

我的类文件( hellojni.class )和java文件( hellojni.java )两者都在 D:\ 驱动器的根目录中。

My class file (hellojni.class) and java file (hellojni.java) both are in the root of D:\ drive.

但每当我运行javah工具时,它都会给我一个错误:

But whenever I run javah tool it gives me an error:


can找不到hellojni的类文件

could not find class file for hellojni

我尝试提供类路径,但没有得到任何头文件。

I tried by providing classpath as well but not getting any header file.

推荐答案

我怀疑问题是你的类有一个包,你试图从带有类文件的目录运行命令而不是包根

Samhain的例子有效,因为他的 MyClass.java 不包含包,而我怀疑你的确如此。

Samhain's example works because his MyClass.java contains no package, whereas I suspect yours does.

例如,假设我们在 c:\ src \ com \ example &\\ MyClass.java中有以下文件

package com.example;

public class MyClass {
    public native void myMethod();
}

转到命令行并执行以下命令:

Go to the command line and execute the following:

c:\src\com\example>javac MyClass.java

c:\src\com\example>dir

 Directory of C:\src\com\example

2015-02-23  03:17 PM    <DIR>          .
2015-02-23  03:17 PM    <DIR>          ..
2015-02-23  03:20 PM               219 MyClass.class
2015-02-23  03:17 PM                84 MyClass.java

c:\src\com\example>javah MyClass
Error: Could not find class file for 'MyClass'.

c:\src\com\example>cd c:\src

c:\src>javah com.example.MyClass

c:\src>dir
 Directory of C:\src

2015-02-23  03:18 PM    <DIR>          .
2015-02-23  03:18 PM    <DIR>          ..
2015-02-23  03:16 PM    <DIR>          com
2015-02-23  03:18 PM               449 com_example_MyClass.h

成功!

这篇关于Javah工具错误:无法找到hellojni的类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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