应用程序似乎工作得很好,但是当我想执行这个api的可运行jar时,它就不工作了。所以我用C:...\jr6\bin\java.exe-jar C:\user\olivier\desktop\appli.jar执行我的jar
然后第一个问题是关于两个罐子,我必须倒置,使他们工作。(2个xstream JAR)
现在,一个新的错误出现了。应用程序似乎无法加载文件名language.properties
protected Properties readPropertiesFile(final String filename,final int level){
if (filename == null) {
return null;
}
//if first level (0) then clear the list of already loaded files
if (level == 0) {
this.alreadyLoadedFiles.clear();
}
InputStreamReader stream = null;
try {
//Try to open a connection with the properties file
stream = new InputStreamReader(new FileInputStream(filename), "UTF-8");
} catch (FileNotFoundException e) {
//Try to find the specified propertie file in Classpath
this.logServices.severe("Cannot found the '"+filename+"' properties file.");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
this.logServices.severe("UnsupportedEncodingException '"+filename+"' properties file encoding in UTF-8");
}
//Read the properties file
Properties props = new Properties();
try {
props.load(stream);
//Add the file in the list of already loaded file
this.alreadyLoadedFiles.add(filename);
} catch (Exception e) {
props = null;
this.logServices.severe("Cannot read the '"+
filename+"' properties file : "+e.getMessage());
} finally {
try {
stream.close();
} catch (IOException e) {
}
}
//Search for the include Tag in properties file
this.readIncludePropertiesFiles(props, (level+1));
return props;
不管是抽象的还是字符串形式的路径名,都可以是绝对的或相对的。绝对路径名是完整的,因为不需要其他信息来定位它所表示的文件。相反,相对路径名必须根据从其他路径名获取的信息进行解释。
缺省情况下,java.io包中的类总是根据当前用户目录解析相对路径名。该目录由系统属性user.dir命名,通常是调用Java虚拟机的目录。源JavaDoc
因此,如果将文件放在jar文件中,路径可能无法解析,这取决于运行程序的目录。因此,在类路径中访问文件的更好方法是如下所示:
InputStream is = this.getClass().getResourceAsStream(filename);
InputStreamReader stream = new InputStreamReader(is, "UTF-8");
stream = new InputStreamReader(new FileInputStream(filename), "UTF-8");
我在为D写一个角色构建器 我正在使用InputStream将javafx Image构造加载到ImageView构造函数[new ImageView(new Image(getClass(). getResourceAsStream(...)))]中;当我加载一些. jpeg图像时,它可以工作,但当我对. png图像执行相同的过程时就不行了 我已经尝试了这里描述的许多关于StackOverflow
我试图在Springboot应用程序中使用logback-spring.xml创建日志记录功能,但是无法读取logback-spring.xml文件中的属性值(例如:log.dest.path)。 我通过@PropertySource基于概要文件动态加载不同环境(开发、阶段、生产)的属性文件(YAML)。概要分析工作正常,并且加载了正确的YAML文件(例如:- application.dev.ym
当我构建一个jar文件并运行它时,由于找不到图像图标,它显示一个空指针异常 这是我运行jar文件时得到的错误 但是当我在NetBeans中运行这个项目时,它运行良好 这是我列出罐子里所有文件时的输出
我已经创建了一个SpringBoot应用程序,并且我将Application.properties放置在jar文件的同一个文件夹中。这是文件的内容: 当我在jar文件夹外运行/bin/java-jar/opt/apl/org.web.exemplo-java-maven.1.0.0-90/org.web.exemplo-java-maven-1.0.0-90.jar时,它不读取applicatio
问题内容: 我有一个JAR文件,我的所有代码都已存档以便运行。我必须访问一个属性文件,每次运行前都需要对其进行更改/编辑。我想将属性文件保留在JAR文件所在的目录中。无论如何,有没有告诉Java从该目录中提取属性文件? 注意:我不想将属性文件保留在主目录中或在命令行参数中传递属性文件的路径。 问题答案: 因此,你希望将与主/可运行jar相同文件夹中的文件视为文件,而不是作为主/可运行jar的资源。
问题内容: 我只是想到了一种不那么直截了当的方法: 我可以以某种方式将JAR资源列表转换为内部JAR URL列表,然后可以使用openConnection()打开它。 问题答案: 您使用JarFile打开一个Jar文件。有了它,您可以使用’getEntry(String name)’或’entires’来获取ZipEntry或JarEntry(它们可以看作同一东西)。收到条目后,可以通过调用’ J