集册 Java实例教程 在Jar包中获取类名

在Jar包中获取类名

欢马劈雪     最近更新时间:2020-01-02 10:19:05

534
在Jar包中获取类名

/* 

 * ClassListHelper.java

 * Christoph Egger

 * $Revision$

 * 

 * Copyright (C) 2010 FTW (Telecommunications Research Center Vienna)

 * 

 *

 * This file is part of BIQINI, a free Policy and Charging Control Function

 * for session-based services.

 *

 * BIQINI is free software; you can redistribute it and/or modify

 * it under the terms of the GNU General Public License as published by

 * the Free Software Foundation; either version 2 of the License, or

 * (at your option) any later version

 *

 * For a license to use the BIQINI software under conditions

 * other than those described here, or to purchase support for this

 * software, please contact FTW by e-mail at the following addresses:

 * fpcc@ftw.at ??

 *

 * BIQINI is distributed in the hope that it will be useful,

 * but WITHOUT ANY WARRANTY; without even the implied warranty of

 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ?See the

 * GNU General Public License for more details.

 *

 * You should have received a copy of the GNU General Public License 

 * along with this program; if not, write to the Free Software 

 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA ?02111-1307 ?USA

 *///来 自 n o w j a v a . c o m - 时  代  Java

//package com.nowjava;


import java.io.FileInputStream;


import java.util.ArrayList;

import java.util.jar.JarEntry;

import java.util.jar.JarInputStream;


public class Main {



    public static ArrayList<String> getClassNamesInJarPackage(

            String _JarName, String _PackageName) {
            /**
             from
            * 时 代 J a v a 
            **/

        ArrayList<String> nameList = new ArrayList<String>();

        _PackageName = _PackageName.replaceAll("\\.", "/");

        System.out.println("Jar " + _JarName + " for " + _PackageName);

        try {

            JarInputStream jarFile = new JarInputStream(

                    new FileInputStream(_JarName));

            JarEntry jarEntry;

            while (true) {

                jarEntry = jarFile.getNextJarEntry();

                if (jarEntry == null) {

                    break;

                }

                
展开阅读全文