Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Mimetypes to MimetypesFileTypeMap
    text
    copied!<p>I'm having trouble adding Mimetypes to MimetypesFileTypeMap. I've tried adding a META-INF/mime.types file just like the <a href="http://www.gnu.org/software/classpathx/jaf/javadoc/javax/activation/MimetypesFileTypeMap.html" rel="nofollow noreferrer">Documentation</a> says to. but it doesn't seem like it is getting read by MimetypesFileTypeMap.</p> <p>Am I missing something? </p> <p>It is a Spring/Maven Web project. Any help would be appreciated!</p> <hr> <p>Even stranger side point. A passerby (Andrew T.) was doing some investigation into MIME types just the other day &amp; uncovered this documentation in the <code>MimetypesFileTypeMap</code> JavaDocs.</p> <hr> <h2>MIME types file search order:</h2> <p>The <code>MimetypesFileTypeMap</code> looks in various places in the user's system for MIME types file entries. When requests are made to search for MIME types in the <code>MimetypesFileTypeMap</code>, it searches MIME types files in the following order:</p> <ol> <li>Programmatically added entries to the <code>MimetypesFileTypeMap</code> instance.</li> <li>The file <code>.mime.types</code> in the user's home directory.</li> <li>The file <code>&lt;java.home&gt;/lib/mime.types</code>.</li> <li>The file or resources named <code>META-INF/mime.types</code>.</li> <li>The file or resource named <code>META-INF/mimetypes.default</code> (usually found only in the <code>activation.jar</code> file). <strong>(A)</strong></li> </ol> <p><strong>(A) As demonstrated by the <a href="https://stackoverflow.com/questions/6308142/adding-mimetypes-to-mimetypesfiletypemap/6333057#6333057">code posted by jwrobel</a>, the Jar actually seems to be the <code>resources.jar</code> on at least two systems (with JDKs).</strong></p> <hr> <p>So given this source..</p> <pre><code>import java.io.File; import javax.activation.MimetypesFileTypeMap; class TestMime { public static void main(String[] args) { System.out.println(System.getProperty("java.version")); File f = new File(System.getProperty("java.home"), "lib"); f = new File(f, "mime.types"); System.out.println(f.exists() + " \t - " +f); f = new File(System.getProperty("user.home"), ".mime.types"); System.out.println(f.exists() + " \t - " +f); MimetypesFileTypeMap mfm = new MimetypesFileTypeMap(); System.out.println(mfm.getContentType("a.js")); System.out.println(mfm.getContentType("a.png")); System.out.println(mfm.getContentType("a.jpg")); System.out.println(mfm.getContentType("a.au")); System.out.println(mfm.getContentType("a.htm")); } } </code></pre> <p>..we can rule out '1' - programmatically added. We can also forget 4 &amp; 5 if we run it from the command line in a directory with no <code>META-INF</code>, no <code>activation.jar</code> on the class-path. Which only leaves options 2 &amp; 3.</p> <p>Yet the output of this source is..</p> <pre><code>1.6.0 false - C:\Program Files\Java\jdk1.6.0\jre\lib\mime.types false - C:\Users\Andrew\.mime.types application/octet-stream application/octet-stream image/jpeg audio/basic text/html Press any key to continue . . . </code></pre> <p>I.E. The <code>false</code> result on both files that could be the source of the MIME mappings shown for the file strings, suggest those last two source of info. don't exist. So where the heck is the information coming from?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload