I am wondering why some resources files are put under the META-INF directory in the JAR? I am always put the resources like test.properties under the root diretcory. Any advantage to put them in the META-INF?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Lot of Java (EE) APIs have a contract that when you put a specific configuration/metadata file in the
META-INFfolder of your (or a 3rd party) JAR, then the API will automatically do the API-specific job, such as scanning classes, preloading specific classes and/or executing specific code based on the meta information.An example provided by the standard Java SE API is the
ServiceLoader. Among others, the JDBC 4.0 compatible drivers implement this. This way just dropping the JDBC driver JAR file folder will automatically load the driver class during Java application’s startup/initialization without the need for any manualClass.forName("com.example.Driver")line in your code.Further there is also the Java EE 6 provided JSF 2.0 API which scans during application’s startup all JAR files for a
faces-config.xmlfile in theMETA-INFfolder. If present, it then will then take it as a hint to scan the entire JAR file for classes implementing the JSF specific annotations like@ManagedBeanso that they get auto-instantiated and auto-configured. This saves time in potentially expensive job of scanning thousands of classes in all JARs in the entire classpath. In older versions of those API’s the configuration was usually done by (verbose) XML files.All with all, the major goal is to save the developer from code and/or configuration boilerplate. The JAR’s
META-INFfolder is used for configuration files/hints. Some API’s indeed also put static files/resources in there for own use. TheMETA-INFfolder is also part of the classpath, so the loading of those files by the classloader is easy done.