Monday, September 20, 2010

How to view the MANIFEST.MF file of a jar

If you do not work with the command line with jars a lot it is easy to forget what the options are. I was surprise to learn that if you do a search for "How to view the MANIFEST.MF file of a jar" you do not find anything that simply tells you how (or even how to in a round about way). I hope this post will solve that.

Say you have a jar file like http.jar from the NetBeans Flower Store example.

View contents of jar

If you want to view the contents of the jar simply use jar tf  jar
mike@mike-laptop:~$ jar tf /home/mike/NetBeansProjects/FlowerRest/build/web/WEB-INF/lib/http.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/sun/
com/sun/net/
com/sun/net/httpserver/
com/sun/net/httpserver/spi/
com/sun/net/httpserver/spi/HttpServerProvider$1.class
com/sun/net/httpserver/spi/HttpServerProvider.class
com/sun/net/httpserver/HttpServer.class
com/sun/net/httpserver/HttpsServer.class
com/sun/net/httpserver/HttpHandler.class
com/sun/net/httpserver/HttpContext.class
com/sun/net/httpserver/HttpsConfigurator.class
com/sun/net/httpserver/HttpExchange.class
com/sun/net/httpserver/Filter$Chain.class
com/sun/net/httpserver/Filter.class
com/sun/net/httpserver/Authenticator$Result.class
com/sun/net/httpserver/Authenticator$Failure.class
com/sun/net/httpserver/Authenticator$Success.class
com/sun/net/httpserver/Authenticator$Retry.class
com/sun/net/httpserver/Authenticator.class
com/sun/net/httpserver/HttpsParameters.class
com/sun/net/httpserver/Headers.class
com/sun/net/httpserver/HttpPrincipal.class
com/sun/net/httpserver/HttpsExchange.class
com/sun/net/httpserver/BasicAuthenticator.class
com/sun/net/httpserver/Base64.class
sun/
sun/net/
sun/net/httpserver/
sun/net/httpserver/ChunkedOutputStream.class
sun/net/httpserver/ExchangeImpl.class
sun/net/httpserver/Request$ReadStream.class
sun/net/httpserver/Request$WriteStream.class
sun/net/httpserver/Request.class
sun/net/httpserver/HttpConnection.class
sun/net/httpserver/LeftOverInputStream.class
sun/net/httpserver/PlaceholderOutputStream.class
sun/net/httpserver/ServerImpl$DefaultExecutor.class
sun/net/httpserver/ServerImpl$Dispatcher.class
sun/net/httpserver/ServerImpl$Exchange$LinkHandler.class
sun/net/httpserver/ServerImpl$Exchange.class
sun/net/httpserver/ServerImpl$ServerTimerTask.class
sun/net/httpserver/ServerImpl$1.class
sun/net/httpserver/ServerImpl.class
sun/net/httpserver/TimeSource.class
sun/net/httpserver/HttpContextImpl.class
sun/net/httpserver/SSLStreams$Parameters.class
sun/net/httpserver/SSLStreams$WrapperResult.class
sun/net/httpserver/SSLStreams$BufType.class
sun/net/httpserver/SSLStreams$EngineWrapper.class
sun/net/httpserver/SSLStreams$InputStream.class
sun/net/httpserver/SSLStreams$OutputStream.class
sun/net/httpserver/SSLStreams$1.class
sun/net/httpserver/SSLStreams.class
sun/net/httpserver/ContextList.class
sun/net/httpserver/Event.class
sun/net/httpserver/AuthFilter.class
sun/net/httpserver/SelectorCache$1.class
sun/net/httpserver/SelectorCache$SelectorWrapper.class
sun/net/httpserver/SelectorCache$CacheCleaner.class
sun/net/httpserver/SelectorCache.class
sun/net/httpserver/WriteFinishedEvent.class
sun/net/httpserver/HttpError.class
sun/net/httpserver/DefaultHttpServerProvider.class
sun/net/httpserver/FixedLengthInputStream.class
sun/net/httpserver/UndefLengthOutputStream.class
sun/net/httpserver/Code.class
sun/net/httpserver/ServerConfig.class
sun/net/httpserver/StreamClosedException.class
sun/net/httpserver/UnmodifiableHeaders.class
sun/net/httpserver/HttpExchangeImpl.class
sun/net/httpserver/HttpsExchangeImpl.class
sun/net/httpserver/HttpServerImpl.class
sun/net/httpserver/HttpsServerImpl.class
sun/net/httpserver/ChunkedInputStream.class
sun/net/httpserver/FixedLengthOutputStream.class

There it is the MANIFEST.MF file, I've highlighted it in red.

Get MANIFEST.MF from jar

To extract the MANIFEST.MF file simply use jar xf  jar META-INF/MANIFEST.MF
mike@mike-laptop:~$ jar xf /home/mike/NetBeansProjects/FlowerRest/build/web/WEB-INF/lib/http.jar META-INF/MANIFEST.MF

View MANIFEST.MF from jar

To view the file use cat META-INF/MANIFEST.MF or edit META-INF/MANIFEST.MF in Windows.
mike@mike-laptop:~$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)

Easy enough.  The xf option on the jar, extracts the file so you may want to delete the extracted META-INF/MANIFEST.MF afterwards.