使用PDF文档将项目导出到Runnable JAR文件中

时间:2021-04-11 13:28:36

I have project that I created and it contains a help button that opens a .pdf file with my documentation. The code for the button is the following

我有我创建的项目,它包含一个帮助按钮,用我的文档打开.pdf文件。该按钮的代码如下

URL loc = Actions.class.getResource("Documentation/test.pdf");
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + loc);

When I run and execute my application using eclipse and click on the button it opens the document fine in adobe reader. After I export my project into a Runnable JAR File via eclipse and click on the button it doesn't do anything. Is there something that I need to add in order to make this work?

当我使用eclipse运行并执行我的应用程序并单击按钮时,它会在adobe reader中打开文档。在我通过eclipse将项目导出到Runnable JAR文件并单击按钮后它没有做任何事情。为了使这项工作,我需要添加一些东西吗?

I just opened the jar file using 7zip and my test.pdf document does show up in there.

我刚刚使用7zip打开了jar文件,我的test.pdf文件确实显示在那里。

2 个解决方案

#1


0  

This may be because the pdf file is inside the jar and returned URL from method getResource can not be recognized by external program.

这可能是因为pdf文件位于jar内部,并且方法getResource返回的URL无法被外部程序识别。

You can do a print of "loc" to see what the URL looks like when it's in the jar file.

您可以打印“loc”以查看URL文件中的URL。

#2


0  

The default behavior and intentions behind a jar file are for packaging of files (Java) into a compressed format. If you want to have an executable type jar then you need to include a manifest file that specifies your main Java class (the class that contains the main(). From here you can code the logic to launch your pdf's.

jar文件背后的默认行为和意图是将文件(Java)打包成压缩格式。如果你想拥有一个可执行类型jar,那么你需要包含一个清单文件来指定你的主Java类(包含main()的类。从这里你可以编写逻辑来启动你的pdf。

#1


0  

This may be because the pdf file is inside the jar and returned URL from method getResource can not be recognized by external program.

这可能是因为pdf文件位于jar内部,并且方法getResource返回的URL无法被外部程序识别。

You can do a print of "loc" to see what the URL looks like when it's in the jar file.

您可以打印“loc”以查看URL文件中的URL。

#2


0  

The default behavior and intentions behind a jar file are for packaging of files (Java) into a compressed format. If you want to have an executable type jar then you need to include a manifest file that specifies your main Java class (the class that contains the main(). From here you can code the logic to launch your pdf's.

jar文件背后的默认行为和意图是将文件(Java)打包成压缩格式。如果你想拥有一个可执行类型jar,那么你需要包含一个清单文件来指定你的主Java类(包含main()的类。从这里你可以编写逻辑来启动你的pdf。