所有
我在里面创建了一个包含以下MANIFEST.MF的jar文件:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)
Main-Class: my.Main
Class-Path: . lib/spring-core-3.2.0.M2.jar lib/spring-beans-3.2.0.M2.jar
Run Code Online (Sandbox Code Playgroud)
在它的根目录中有一个名为my.config的文件,它在我的spring-context.xml中引用,如下所示:
<bean id="..." class="...">
<property name="resource" value="classpath:my.config" />
</bean>
Run Code Online (Sandbox Code Playgroud)
如果我运行jar,除了加载特定文件外,一切看起来都很好:
Caused by: java.io.FileNotFoundException: class path resource [my.config] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/D:/work/my.jar!/my.config
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at eu.stepman.server.configuration.BeanConfigurationFactoryBean.getObject(BeanConfigurationFactoryBean.java:32)
at eu.stepman.server.configuration.BeanConfigurationFactoryBean.getObject(BeanConfigurationFactoryBean.java:1)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 22 more
Run Code Online (Sandbox Code Playgroud)
有小费吗?
我正在使用Spring Boot和json-schema-validator.我正在尝试读取jsonschema.json从该resources文件夹调用的文件.我尝试了几种不同的方法,但我无法让它发挥作用.这是我的代码.
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("jsonschema.json").getFile());
JsonNode mySchema = JsonLoader.fromFile(file);
Run Code Online (Sandbox Code Playgroud)
这是文件的位置.
在这里,我可以在文件classes夹中看到该文件.
但是当我运行代码时,我得到以下错误.
jsonSchemaValidator error: java.io.FileNotFoundException: /home/user/Dev/Java/Java%20Programs/SystemRoutines/target/classes/jsonschema.json (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
我在代码中做错了什么?
我正在尝试为我的项目设置配置位置,但我不断收到以下错误:
java.io.FileNotFoundException:无法打开类路径资源[main/resources/app-context.xml],因为它不存在
我的项目设置如下:

我将我的代码设置为:
ApplicationContext context = new ClassPathXmlApplicationContext(configLocation: "main/resources/app-context.xml");
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我正在尝试使用Spring资源加载器读取文本文件,如下所示:
Resource resource = resourceLoader.getResource("classpath:\\static\\Sample.txt");
Run Code Online (Sandbox Code Playgroud)
它在eclipse中运行应用程序时工作正常,但是当我打包应用程序然后使用java -jar运行它时,我得到文件未找到异常:
java.io.FileNotFoundException: class path resource [static/Sample.txt] cannot be resolved to absolute file path because it does not reside in the
file system: jar:file:/C:/workspace-test/XXX/target/XXX-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/static/Sample.txt
Run Code Online (Sandbox Code Playgroud)
我解压缩了Sample所在的Jar文件:XXX-0.0.1-SNAPSHOT\BOOT-INF\classes\static\Sample.txt
有谁可以帮助我吗 ?
提前致谢!