Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3239050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:55:28+00:00 2026-05-17T17:55:28+00:00

I have a simple service called BuildNumberService which would be instantiated by spring. I’m

  • 0

I have a simple service called BuildNumberService which would be instantiated by spring.

I’m trying to find the cleanest code for the class to find out the MANIFEST.MF file from the jar file it has been packaged into.

The code has to run inside a servlet container.

@Service
public class BuildNumberService {

    private static final String IMPLEMENTATION_BUILD = "Implementation-Build";

    private String version = null;

    public BuildNumberService() {

      // find correct manifest.mf
      // ?????


      // then read IMPLEMENTATION_BUILD attributes and caches it.
       Attributes mainAttributes = mf.getMainAttributes();
       version = mainAttributes.getValue(IMPLEMENTATION_BUILD);
    }

    public String getVersion() {
        return this.version;
    }
}

How would you do that ?

Edit: Actually, what I’m trying to do, is, find a resource by name which sits in the same package as the actual class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:55:28+00:00Added an answer on May 17, 2026 at 5:55 pm

    Well if you know the jar is on the file system (e.g. not inside a war) and you also know that the security manager gives you the permission to access a class’ protection domain, you can do it like this:

    public static InputStream findManifest(final Class<?> clazz) throws IOException,
        URISyntaxException{
        final URL jarUrl =
            clazz.getProtectionDomain().getCodeSource().getLocation();
        final JarFile jf = new JarFile(new File(jarUrl.toURI()));
        final ZipEntry entry = jf.getEntry("META-INF/MANIFEST.MF");
        return entry == null ? null : jf.getInputStream(entry);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple local service that I'm trying to bind to my
I have a simple WCF service method: [OperationContract] public SetupGameResult SetupGame(long player1Id, long player2Id,
I have a Service model with title:string description:string date:datetime. I would like to implement
Hi Im using silverlight ria services and trying to called a domain service method
Say I have a simple WCF application that the client calls in order to
I have two webapps: a web-service client and a server (both CXF-based, using the
I have just started using services in Android and I have a made a
All, I have a very general question regarding a future project. I need to
I have a c# solution with 3 projects - Data, WCF and UI. The
I am a bit new to Android. What I need to do is send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.