使用 Eclipse 将 JavaHelp 系统集成到我的应用程序中时,findHelpSet 返回空 URL
我试图将 JavaHelp 包含在 Eclipse 下开发的应用程序中。
我做了以下事情:
- 下载并解压 JavaHelp 库 到子文件夹中我的项目工作区。
将以下库的 JAR 添加到我的项目类路径(
<块引用>属性 -> Java 构建路径 -> 库 -> 添加外部 JAR
):jh.jar
jhall.jar
jhbasic.jar
jsearch.jar
我尝试创建两个名为 help_folder 的文件夹(
New->Folder
)和一个源文件夹(New->Source名为 help_source_folder 的文件夹
),并在其中放入一个名为 Master.hs 的示例文件(我从 JavaHelp 存档中获取它)。
然后,在我的应用程序内部,我执行了以下操作:
try {
ClassLoader loader = this.getClass().getClassLoader();
URL url = HelpSet.findHelpSet(loader, "Master.hs");
//alternatively : URL url = HelpSet.findHelpSet(loader, "help_folder/Master.hs");
//alternatively: URL url = HelpSet.findHelpSet(loader, "help_source_folder/Master.hs");
JHelp jhelp = new JHelp(new HelpSet(loader, url));
} catch (HelpSetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
现在问题如下:无法创建 HelpSet 对象,因为 findHelpSet()
方法返回 null
URL。
我不知道如何解决这个问题。有人能让我走上正确的方向吗?
I'm trying to include JavaHelp inside my application developed under Eclipse.
I did the following things:
- Download and extract the JavaHelp library in a sub-folder of my project workspace.
Added the following library's JARs to my project class path (
Properties->Java Build Path->Libraries->Add External JARs
):jh.jar
jhall.jar
jhbasic.jar
jsearch.jar
I tried to create both folder (
New->Folder
) called help_folder and a Source Folder (New->Source Folder
) called help_source_folder, and put inside them a file of example called Master.hs (I took it from the JavaHelp archive).
Then from inside my application I did the following:
try {
ClassLoader loader = this.getClass().getClassLoader();
URL url = HelpSet.findHelpSet(loader, "Master.hs");
//alternatively : URL url = HelpSet.findHelpSet(loader, "help_folder/Master.hs");
//alternatively: URL url = HelpSet.findHelpSet(loader, "help_source_folder/Master.hs");
JHelp jhelp = new JHelp(new HelpSet(loader, url));
} catch (HelpSetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Now the problem is the following: HelpSet object cannot be created because a null
URL is returned by findHelpSet()
method.
I have no idea on how solve this. Can someone put me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您创建的文件夹位于项目的源文件夹内(默认为“src”)。如果不是,那么在构建项目时它不会包含在输出文件夹(默认为“bin”)中。
Make sure the folder you create is inside your project's source folder (defaults to 'src'). If it's not then it won't be included in the output folder (defaults to 'bin') when it builds the project.
findHelpSet() 方法返回 null 有两个原因:
在类路径中找不到主帮助集文件。当我使用 IDE 时,这种情况经常发生在我身上,因为它们将所有类编译到某个工作目录中,并且经常“忘记”将具有“未知”扩展名的文件复制到那里,而 hs 是一个扩展名,除非您手动将其添加到 IDE 中,否则很可能是未知的。
它可以找到它,但无法读取它。这可能是因为一些安全问题。另外,空文件被认为是无法读取的文件,在我看来这是一个错误,因此请确保您的主文件中包含一些数据。
There are two reasons findHelpSet() method will return null:
It couldn't find Master help set file in your classpath. It happened to me a lot when I was using IDEs because they compile all your classes into some working directory and often 'forget' to copy files there with 'unknown' extensions, and hs is an extension that is most probably unknown unless you add it to your IDE manually.
It could find it but it could not read it. This could be because of some security issues. Also an empty file is considered a file that could not be read from, which is a bug IMO, so make sure your Master file has some data in it.