クラスパス外のカスタムの場所から javahelp コンテンツをロードできるようにしたいと考えています。この場所は、アプリケーションの実行中に変更される可能性があり、共有ネットワーク デバイス上にある可能性があります。
残念なことに、HelpSet クラスはクラスローダーを期待しているので、私のヘルプセット ファイルはクラスパスにある必要があると思いますか、それとも別の方法がありますか? 前もって感謝します。
これは、独自の ClassLoader を作成して使用することで可能になります。使用する可能性が最も高い ClassLoader の候補はURLClassLoaderです。
おそらく、次のようなコードがあります。
JHelp helpViewer = null;
try {
// Get the classloader of this class.
ClassLoader cl = JavaHelpTest.class.getClassLoader();
// Use the findHelpSet method of HelpSet to create a URL referencing the helpset file.
// Note that in this example the location of the helpset is implied as being in the same
// directory as the program by specifying "jhelpset.hs" without any directory prefix,
// this should be adjusted to suit the implementation.
URL url = HelpSet.findHelpSet(cl, "jhelpset.hs");
// Create a new JHelp object with a new HelpSet.
helpViewer = new JHelp(new HelpSet(cl, url));
}
システム クラス パスに基づく行ではなく、共有ディレクトリに基づいて ClassLoader を取得する行を変更する必要があります。だから、このようなもの:
JHelp helpViewer = null;
try {
// Get the class loader of the shared directory. Note that directories are
// required to have a trailing '/' or '\'.
ClassLoader cl = new URLClassLoader(new URL[] {new URL("file:///path/to/share/")});
// Use the findHelpSet method of HelpSet to create a URL referencing the helpset file.
// Note that in this example the location of the helpset is implied as being in the same
// directory as the program by specifying "jhelpset.hs" without any directory prefix,
// this should be adjusted to suit the implementation.
URL url = HelpSet.findHelpSet(cl, "jhelpset.hs");
// Create a new JHelp object with a new HelpSet.
helpViewer = new JHelp(new HelpSet(cl, url));
}