Overriding or changing default MIME types for artifact downloads

By default when Nexus downloads files into proxy repositories it validates that the downloaded file's contents match what is expected based on the file's MIME type. 

This works well for most normal file types, but occasionally you may find that you need to make Nexus aware of new MIME types, or add additional file extensions into ones it already processes.

Nexus 2.3 and newer

Nexus 2.3 contains a new feature which allows you to do this.

To use this feature, just create a file called "nexus.mimetypes" in  "<nexus_root>/nexus/WEB-INF/classes". To add a mime type add a line with this format:

bz2: application/x-bzip2,application/x-bzip

Note that no whitespace is allowed in the comma delimited list of mime types.  The first content type listed is the default, if no accept header is present for the artifact request this will be the content type sent back.

To override a mime type definition use this format:

override.html: text/xhtml,application/xml

The set of default MIME types Nexus 2.3 ships with is as follows:

jar: application/zip
zip: application/zip
war: application/zip
ear: application/zip
pom: application/xml,application/x-maven-pom,text/xml
xml: application/xml,text/xml
tar: application/x-tar
swc: application/zip
swf: application/x-shockwave-flash
gz: application/x-gzip,application/x-tgz
tgz: application/x-tgz,application/x-gzip
bz2: application/x-bzip2
tbz: application/x-bzip2

You will need to restart nexus after making changes to the nexus.mimetypes file.

Nexus 2.2 and older

Perform the following steps:

1) Extract and the default mime-type.properties from the nexus-api.jar. This can be found in BASEDIR/nexus/WEB-INF/lib/nexus-api-2.x.jar.

2) Copy this file into ${nexus_root}/conf (where the nexus.properties and jetty.xml files are located).

3) Edit to add additional MIME type mappings, or change existing ones

4) Restart Nexus

Have more questions? Submit a request

7 Comments

  • 0
    Avatar
    Anders Hammar

    Obviously, it is not only possible to add additional MIME type mappings this way, but also change the default MIME type mappings.

  • 0
    Avatar
    Rich Seddon

    Good point, I've updated the entry to reflect this.

  • 0
    Avatar
    Walter Sigel

    So, there is an other way to add additional mime types ?

     

    I did not found nexus-api !:

    nexus-professional-2.10.0-02/lib/slf4j-api-1.7.6.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-custom-metadata-plugin-2.10.0-02/dependencies/sesame-rio-api-2.3.2.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-custom-metadata-plugin-2.10.0-02/dependencies/sesame-repository-api-2.3.2.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-custom-metadata-plugin-2.10.0-02/dependencies/sesame-sail-api-2.3.2.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-custom-metadata-plugin-2.10.0-02/dependencies/sonatype-indexer-api-1.5.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-custom-metadata-plugin-2.10.0-02/dependencies/sesame-queryparser-api-2.3.2.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-maven-bridge-plugin-2.10.0-02/dependencies/wagon-provider-api-2.4.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-siesta-plugin-2.10.0-02/dependencies/jsr311-api-1.1.1.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-siesta-plugin-2.10.0-02/dependencies/validation-api-1.1.0.Final.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-p2-bridge-plugin-2.10.0-02/dependencies/org.sonatype.p2.bridge.api-1.1.8.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/plugin-repository/nexus-p2-bridge-plugin-2.10.0-02/p2-runtime/bridge/org.sonatype.p2.bridge.api.manifest

    nexus-professional-2.10.0-02/nexus/WEB-INF/lib/jsr250-api-1.0.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/lib/nexus-plugin-api-2.10.0-02.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/lib/nexus-repository-metadata-api-2.10.0-02.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/lib/aether-api-1.13.1.jar

    nexus-professional-2.10.0-02/nexus/WEB-INF/lib/cdi-api-1.0.jar

  • 0
    Avatar
    Rich Seddon

    Nexus 2.10.0-02 is newer than Nexus 2.3, so the "Nexus 2.3 and newer" instructions apply for your installation.

     

    Rich

  • 0
    Avatar
    Walter Sigel

    Does not work!

    Tested with Sonatype Nexus™ Professional Edition, Version: 2.11.2-04

    1. Added file called "nexus.mimetypes" in  "<nexus\_root>/nexus/WEB-INF/classes" with one line:
      #) cat nexus.mimetypes
      ivy: application/xml,text/xml
    2. Nexus restarted
    3. Download a file named org/apache/ivy/ivy/2.1.0/ivy-2.1.0.ivy

    Download of attached file:

    With "File Content Validation" set "False", download is OK

    With "File Content Validation" set "True", download is NOK

    <?

  • 0
    Avatar
    Rich Seddon

    By default file content validation doesn't work for XML files.

    The primary function of file content validation is to protect against misbehaving remote servers which return HTTP 200 and a human readable HTML error page when they should be returning 404. Without file content validation these HTML pages get stored as artifacts, which results in a big mess.  Unfortunately it isn't easy to distinguish between XML and HTML, given how badly formed HTML pages often are.

    You can enable file content type checking for XML files by adding the following line to $NEXUS_HOME/nexus.properties:

    org.sonatype.nexus.proxy.maven.MavenFileTypeValidator.relaxedXmlValidation=true

    The downside to this is that it will require that XML files start with a valid XLM preamble, such as:

    <?xml version="1.0" encoding="UTF-8"?>

    XML files which do not have a valid preamble will be rejected. 

  • 0
    Avatar
    Peter Lynch

    We are closing this article for comments.

    If you have a support license, please contact us by submitting a support ticket.

    If you do not have a support license, please use our Nexus Users List or our other free support resources.

Article is closed for comments.
Powered by Zendesk