`

How to know the main class of a jar file?

阅读更多

Easy. Here is an implementation from Hadoop.

java 代码
  1. /**  
  2.  * A micro-application that prints the main class name out of a jar file.  
  3.  * @author Owen O'Malley  
  4.  */  
  5. public class PrintJarMainClass {   
  6.      
  7.   /**  
  8.    * @param args  
  9.    */  
  10.   public static void main(String[] args) {   
  11.     try {   
  12.       JarFile jar_file = new JarFile(args[0]);   
  13.       if (jar_file != null) {   
  14.         Manifest manifest = jar_file.getManifest();   
  15.         if (manifest != null) {   
  16.           String value = manifest.getMainAttributes().getValue("Main-Class");   
  17.           if (value != null) {   
  18.             System.out.println(value.replaceAll("/""."));   
  19.             return;   
  20.           }   
  21.         }   
  22.       }   
  23.     } catch (Throwable e) {   
  24.       // ignore it   
  25.     }   
  26.     System.out.println("UNKNOWN");   
  27.     System.exit(1);   
  28.   }   
  29.      
  30. }  
分享到:
评论

相关推荐

    How to count the number of lines in a text file

    How to count the number of lines in a text file

    HOW TO IMPROVE YOUR BUSINESS LETTERS

    If the letter came to you, how would you respond? Be pleasant; try to turn negative statements into positive ones. 4. Say it Plainly Phrases like “in compliance with your request” and “enclosed ...

    Getting to Know Vue js

    You’ll also explore how to use Single File Components and the Vue.js Command Line Interface (CLI) to build components in a single file and add in build tools as you see fit. Getting started with a ...

    Getting to Know Vue.js

    You’ll also explore how to use Single File Components and the Vue.js Command Line Interface (CLI) to build components in a single file and add in build tools as you see fit. Getting started with a ...

    How_to_write_and_publish_a_scientific_paper

    How to write and publish a scientific paper ContentsChapter 1 What Is Scientific Writing? Chapter 2 Origins of Scientific Writing Chapter 3 What Is a Scientific Paper? Chapter 4 How to Prepare the ...

    How to Write a World Class Paper

    How to Write a World Class Paper

    This demonstrates how to retrieve the file size from a speci

    This demonstrates how to retrieve the file size from a specified file.

    How to record the trace file in QUALNET

    How to record the trace file in QUALNET The Tracing Scheme Exploration

    how to update the CSS of the master page

    how to update the CSS of the master page: This guid tells you how to update the CSS file so that to change the style of the menu which shows in the master page.

    how to make sense of any mess

    How to Make Sense of Any Mess: Information Architecture for Everybody Abby Covert Everything is getting more complex. It is easy to be overwhelmed by the amount of information we encounter each ...

    数据结构作业Hash表

    To complete this assessment, you need to complete the implementation of class Dictionary and complete the spell checking program contained in main.cpp. Following is an ordered list of steps that ...

    2012年MCM A题outstanding

    参赛资料指导PROBLEM A: The Leaves of a Tree "How much do the leaves on a tree weigh?" How might one estimate the actual weight of the leaves (or for that matter any other parts of the tree)? How might...

    Java邮件开发Fundamentals of the JavaMail API

    The first part of the API is the focus of this course --basically, how to send and receive messages independent of the provider/protocol. * The second part speaks the protocol-specific languages, ...

    How to Write a Better Thesis 3rd Edition

    working with software, and purposeful writing of each of the different kinds of chapters, and finishes with a focus on revision, dissemination and deadlines. How to Write a Better Thesis presents a ...

    This demonstrates how to change the height of a combobox’s

    This demonstrates how to change the height of a combobox’s drop-down height using API.

    Think Perl 6: How to Think Like a Computer Scientist

    Think Perl 6: How to Think Like a Computer Scientist by Laurent Rosenfeld English | 8 May 2017 | ASIN: B0716P9W11 | 466 Pages | AZW3 | 1.02 MB Want to learn how to program and think like a computer ...

    how to solve it

    George Polya revealed how the mathematical method of demonstrating a proof or finding an unknown can be of help in attacking any problem that can be "reasoned" out - from building a bridge to winning...

    uipath level 2参考答案.docx

    5. How can the processes in a schedule be assigned to the robots in a specific environment? 6. Which options and actions can be triggered on the Packages page? 7. Which options can be used to end ...

    How to use SFTP

    The topic How to use SFTP (with client validation - password authentication) discusses the simplest form of client authentication, via password. In public key authentication, SSH clients and ...

Global site tag (gtag.js) - Google Analytics