Java 在JAR中放置配置文件的位置?

Java 在JAR中放置配置文件的位置?,java,jar,classpath,slf4j,manifest.mf,Java,Jar,Classpath,Slf4j,Manifest.mf,我的JAR当前具有以下结构: myapp.jar META-INF MANIFEST.MF net myapp MyAppDriver.class (fully qualified as net.myapp.MyAppDriver) <lots of other classes> myapp.jar META-INF MANIFEST.MF 网 myapp MyAppDriver.cla

我的JAR当前具有以下结构:

myapp.jar
    META-INF
        MANIFEST.MF
    net
        myapp
            MyAppDriver.class (fully qualified as net.myapp.MyAppDriver)
            <lots of other classes>
myapp.jar
META-INF
MANIFEST.MF
网
myapp
MyAppDriver.class(完全限定为net.myapp.MyAppDriver)
我的应用程序需要从运行时类路径读取一个文件,并根据该文件的内容(SLF4J框架中的
simplelogger.properties
)进行自我配置

我应该将
simplelogger.properties
放在JAR中的什么位置?我是否需要在MANFIEST.MF中设置任何内容?


提前谢谢

您可以将文件放在任何JAR中您想要的任何位置。例如,如果您希望它与
MyAppDriver.class
共存,则可以调用
getClassLoader().getResourceAsStream(“net/myapp/simplelogger.properties”)
以获取该文件的
InputStream
。您不需要清单就可以工作。

尝试将配置文件放在jar文件附近。但是如果你能把它放在jar文件中会更好谢谢@AlekseiBulgak(+1)-罐子里的什么地方?在JAR的根目录下(与
META-INF
net
包处于同一级别)?其他地方?再次感谢!与META-INFAhhh处于同一级别,再次感谢@AlekseiBulgak-因此要确认:我的JAR应该有3个顶级项:(1)simplelogger.properties,(2)net和(3)META-INF?再次感谢!是,如果这不是web应用程序