DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Dynatrace Perform: Day Two
  • No Code Expectations vs Reality
  • Moving From Full-Stack Developer To Web3 Pioneer
  • Import a Function/Module in Dataweave

Trending

  • How to Migrate Vector Data from PostgreSQL to MyScale
  • Five Tools for Data Scientists to 10X their Productivity
  • Information Security: AI Security Within the IoT Industry
  • How To Validate Archives and Identify Invalid Documents in Java

Get the handle on the MANIFEST.MF in a webapp

Nicolas Fränkel user avatar by
Nicolas Fränkel
CORE ·
Jun. 27, 11 · Interview
Like (0)
Save
Tweet
Share
14.33K Views

Join the DZone community and get the full member experience.

Join For Free

Code review is part of my job, and you cannot know the crap I’ve seen. Like someone pointed out, it’s also sometimes the crap I’ve written :-)

In all cases, however, it’s because some developers do not have deep knowledge of how things work: most learnt something (in university or from a senior developer) years ago and don’t challenge this information regularly though technology evolve. Others just google the problem at hand and copy-paste the first snippet in their environment.

This little article is basically a how-to describing the right way to get a handle on the manifest in the context of a web application. It seems easy but there are many ways to do it and as far as I know only one is the right way at this moment.

To begin with, one baaddd way to do it would be this:

InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF");
 
Manifest manifest = new Manifest(inputStream);

Why so? Because dependending on your classloading strategy, you’ll fetch another manifest, that has nothing to do with the web application: for example, the above snippet will incidentally fetch the EAR manifest when using the default classloading strategy (Parent-First).

Another wrong code would be the following, for the same reason:

URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
 
InputStream inputStream = url.openStream();
 
Manifest manifest = new Manifest(inputStream);

Finally, one could also try to get the war as a file, then read inside it: forget this path since we don’t know if the WAR will be wrapped in an EAR or deployed in exploded format (or not).

No, the only way (at the time of the writing of this post) is to use the API provided by an application server:

ServletContext application = getServletConfig().getServletContext();
 
InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF");
 
Manifest manifest = new Manifest(inputStream);

This is it: straightforward use of what a compliant application server gives us. Sources for a webapp example that display the version is included here in Maven/Eclipse format.

 

From http://blog.frankel.ch/get-the-handle-on-the-manifest-mf-in-a-webapp

application Application server IT Manifest (transportation) Snippet (programming) WAR (file format) dev

Opinions expressed by DZone contributors are their own.

Related

  • Dynatrace Perform: Day Two
  • No Code Expectations vs Reality
  • Moving From Full-Stack Developer To Web3 Pioneer
  • Import a Function/Module in Dataweave

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: