简体   繁体   English

Java打开文件-在Eclipse上有效,在可运行的JAR / exe中不起作用

[英]Java opening files - works from Eclipse, doesn't work in runnable JAR/exe

I have some java code that I'm using to open a file: 我有一些用于打开文件的Java代码:

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + output.getAbsolutePath());

It works just fine when I execute it from Eclipse, however, when I export the project to a runnable JAR, the functionality stops working. 当我从Eclipse执行它时,它工作得很好,但是,当我将项目导出到可运行的JAR时,该功能将停止工作。 I've tried various different options to open the file (Desktop.open, ProcessBuilder etc.) all with the same results (Eclipse OK, runnable JAR not). 我尝试了各种不同的选项来打开文件(Desktop.open,ProcessBuilder等),所有这些都具有相同的结果(Eclipse OK,而不是可运行的JAR)。

This exact code previously worked when I exported it in the past (1.5 years ago). 过去(1.5年前)我导出该代码时,以前可以使用。 I believe that was with Java 1.6 and now we're on Java 1.7. 我相信这是在Java 1.6上,现在我们在Java 1.7上。 Not sure if that's the reason though and I don't have the option to compile using previous versions of Java. 不确定这是否是原因,并且我没有选择使用Java的早期版本进行编译的选项。 Any ideas? 有任何想法吗?

thanks for attempting to help. 感谢您的帮助。 I figured out the answer which is quite simply that I'm an idiot :) Opening the file wasn't the problem, the file wasn't being written in the first place, and the reason it wasn't being written was quite simply because the code was set to write it into a nested folder structure which had not yet been created. 我想出了答案,这很简单,因为我是个白痴:)打开文件不是问题,不是首先写文件,而不是写文件的原因很简单因为代码已设置为将其写入尚未创建的嵌套文件夹结构中。 I didn't even think of this because I assumed that any necessary folders specified in the output string would be created automatically. 我什至没有想到这一点,因为我假设输出字符串中指定的所有必要文件夹都将自动创建。 Doh! 卫生署!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在运行时编译Java文件可在Eclipse上运行,但不能从导出的可运行jar文件中运行 - Compiling java file at runtime works on eclipse but doesn't work from an exported runnable jar file Java应用程序在Eclipse上工作正常,但在部署为可运行的jar后它无法正常工作 - a Java application works fine on Eclipse but it doesn't work properly after being deployed as a runnable jar 为什么从Eclipse导出的可运行JAR不起作用? - Why doesn't a runnable JAR exported from Eclipse work? 从Java杀死Linux进程在Runnable JAR中不起作用 - Killing linux process from java doesn't work in Runnable JAR Eclipse Java-程序可以在Eclipse中运行,但不能作为可运行的jar - Eclipse Java - Program works in eclipse but not as runnable jar 当导出可运行的jar程序不起作用时的Eclipse - Eclipse when export runnable jar program doesn't work 从Eclipse导出的可运行JAR文件似乎无法执行 - Exported runnable JAR file from Eclipse doesn't seem to execute 可运行的jar无法从一台机器运行到另一台机器 - Runnable jar doesn't work from one machine to another 通过Eclipse创建一个包含.exe文件的可运行JAR - Creating a runnable JAR which includes .exe files via eclipse 在可运行的jar中导出图像不起作用 - Exporting image in runnable jar doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM