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?
The META-INF directory The manifest file that is used to define extension and package related data. This file is generated by the new "-i" option of the jar tool, which contains location information for packages defined in an application or extension.
It shouldn't be at the project root, but directly under the source folder. At runtime, the persistence. xml file is searched in the classpath, under META-INF. So if you want the META-INF folder to be put at the top of the compiled package tree, you need to put it at the top of the source tree.
You must open minecraft. jar in a program which can edit . zip files (such as 7-zip), then delete the META-INF folder as you would anything else. This should not require administrator privileges, as minecraft.
When you do tamper with it by installing mods, the signature becomes invalid and Minecraft won't start at all. By deleting the META-INF directory, you remove the signature completely. Depending on your security settings, you might get an "unknown publisher" warning, but you'll be able to run it.
Lot of Java (EE) APIs have a contract that when you put a specific configuration/metadata file in the META-INF
folder 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 manual Class.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.xml
file in the META-INF
folder. 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 @ManagedBean
so 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-INF
folder is used for configuration files/hints. Some API's indeed also put static files/resources in there for own use. The META-INF
folder is also part of the classpath, so the loading of those files by the classloader is easy done.
In servlet 3.0, certain static resources are available through the web context, such as .css, java script, and .png files, so you no longer need to use ServletContext getResource() and getResourceAsStream(). For more information, check out web-fragment.xml (https://blogs.oracle.com/swchan/entry/servlet_3_0_web_fragment) which is one resource that covers this subject.
Personally, I prefer to structure my projects the way Maven likes them, with a src/main/resources directory which is part of the application's classpath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With