当前位置: 首页>>代码示例>>Java>>正文


Java JarFile.getManifest方法代码示例

本文整理汇总了Java中java.util.jar.JarFile.getManifest方法的典型用法代码示例。如果您正苦于以下问题:Java JarFile.getManifest方法的具体用法?Java JarFile.getManifest怎么用?Java JarFile.getManifest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.JarFile的用法示例。


在下文中一共展示了JarFile.getManifest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getVersion

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static String getVersion()
{
	try
	{
		String path = VDMJC.class.getName().replaceAll("\\.", "/");
		URL url = VDMJC.class.getResource("/" + path + ".class");
		JarURLConnection conn = (JarURLConnection)url.openConnection();
	    JarFile jar = conn.getJarFile();
		Manifest mf = jar.getManifest();
		String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
		return version;
	}
	catch (Exception e)
	{
		return null;
	}
}
 
开发者ID:nickbattle,项目名称:FJ-VDMJ,代码行数:18,代码来源:VDMJC.java

示例2: loadCorePlugin

import java.util.jar.JarFile; //导入方法依赖的package包/类
void loadCorePlugin(File file, CaoutchoucClassLoader classLoader) {
    try {
        JarFile jarFile = new JarFile(file);
        Manifest manifest = jarFile.getManifest();

        if(manifest == null)
            throw new FileNotFoundException("Jar does not contain manifest");

        String corePlugin = manifest.getMainAttributes().getValue("corePlugin");

        if(corePlugin == null)
            throw new IllegalArgumentException("Manifest does not contain \"corePlugin\" tag");


        Caoutchouc.addInClassLoader(file);
        Class<?> corePluginClass = Class.forName(corePlugin, false, classLoader);

        if(ICorePlugin.class.isAssignableFrom(corePluginClass))
            this.corePluginsClass.add(corePluginClass);

    } catch(Exception exc) {
        System.err.println(String.format("Unable to load core plugin %s", file.getName()));
        exc.printStackTrace();
    }
}
 
开发者ID:Gogume1er,项目名称:caoutchouc,代码行数:26,代码来源:CaoutchoucCorePluginLoader.java

示例3: getVersion

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static String getVersion()
{
	try
	{
		String path = VDMJ.class.getName().replaceAll("\\.", "/");
		URL url = VDMJ.class.getResource("/" + path + ".class");
		JarURLConnection conn = (JarURLConnection)url.openConnection();
	    JarFile jar = conn.getJarFile();
		Manifest mf = jar.getManifest();
		String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
		return version;
	}
	catch (Exception e)
	{
		return null;
	}
}
 
开发者ID:nickbattle,项目名称:FJ-VDMJ,代码行数:18,代码来源:VDMJ.java

示例4: JarFileInfo

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * @param jarFile
 *            Never null.
 * @param simpleName
 *            Used for logging. Never null.
 * @param jarFileParent
 *            Used to make simpleName for logging. Null for top level JAR.
 * @param fileDeleteOnExit
 *            Used only to delete temporary file on exit.
 *            Could be null if not required to delete on exit (top level JAR)
 * @throws JarClassLoaderException
 */
JarFileInfo(JarFile jarFile, String simpleName, JarFileInfo jarFileParent,
            ProtectionDomain pd, File fileDeleteOnExit)
{
    this.simpleName = (jarFileParent == null ? "" : jarFileParent.simpleName + "!") + simpleName;
    this.jarFile = jarFile;
    this.pd = pd;
    this.fileDeleteOnExit = fileDeleteOnExit;
    try {
        this.mf = jarFile.getManifest(); // 'null' if META-INF directory is missing
    } catch (IOException e) {
        // Ignore and create blank manifest
    }
    if (this.mf == null) {
        this.mf = new Manifest();
    }
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:29,代码来源:JarClassLoader.java

示例5: get2thDexSHA1

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * 获取dex2文件的SHA1-Digest值
 *
 * @param context
 * @return
 */
private String get2thDexSHA1(Context context) {
    ApplicationInfo info = context.getApplicationInfo();
    String source = info.sourceDir;
    try {
        JarFile jar = new JarFile(source);
        Manifest mf = jar.getManifest();
        Map<String, Attributes> map = mf.getEntries();
        Attributes a = map.get("classes2.dex");
        return a.getValue("SHA1-Digest");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ymqq,项目名称:CommonFramework,代码行数:21,代码来源:BaseApplication.java

示例6: initOneURL

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected void initOneURL(URL url) {
    List<File> jarFiles = listJarFiles(url);
    if (jarFiles != null) {
        for (File jarFile : jarFiles) {
            try {
                JarFile jar = new JarFile(jarFile);
                Manifest manifest = jar.getManifest();
                if (FatJarClassLoader.isFatJar(manifest)) {
                    URL filePath = jarFile.getCanonicalFile().toURI().toURL();
                    fatJarClassLoaders.add(new FatJarClassLoader(jar, filePath, getParent(), child, nestedDelegate));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:hellojavaer,项目名称:fatjar,代码行数:18,代码来源:FatJarClassLoaderProxy.java

示例7: main

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException,
                                      InvocationTargetException, IllegalAccessException {
    URL url = FatJarClassLoaderUtils.getLocatoin(Main.class);
    File fatJarFile = new File(url.getFile());
    JarFile jar = new JarFile(fatJarFile);
    Manifest manifest = jar.getManifest();
    Attributes attributes = manifest.getMainAttributes();
    String startClass = attributes.getValue(START_CLASS_KEY);
    if (startClass == null || startClass.length() == 0) {
        throw new IllegalArgumentException(START_CLASS_KEY + " is missing");
    }
    ClassLoader classLoader = Main.class.getClassLoader();
    FatJarClassLoader fatJarClassLoader = new FatJarClassLoader(jar, url, classLoader.getParent(), classLoader,
                                                                false, true);
    ClassLoader classLoader1 = FatJarClassLoaderUtils.injectFatJarClassLoader(classLoader, fatJarClassLoader);
    Class<?> mainClazz = Class.forName(startClass, true, classLoader1);
    Method invokeMethod = mainClazz.getMethod("main", String[].class);
    invokeMethod.invoke(null, (Object) args);
}
 
开发者ID:hellojavaer,项目名称:fatjar,代码行数:20,代码来源:Main.java

示例8: testPackageDependencyMayfail

import java.util.jar.JarFile; //导入方法依赖的package包/类
public void testPackageDependencyMayfail() throws Exception {
    //see #63904:
    MockModuleInstaller installer = new MockModuleInstaller();
    MockEvents ev = new MockEvents();
    ModuleManager mgr = new ModuleManager(installer, ev);
    mgr.mutexPrivileged().enterWriteAccess();
    try {
        Manifest mani;
        JarFile jf = new JarFile(new File(jars, "simple-module.jar"));
        try {
            mani = jf.getManifest();
        } finally {
            jf.close();
        }

        Module toFail = mgr.create(new File(jars, "fails-on-non-existing-package.jar"), null, false, false, false);
        Module fixed  = mgr.createFixed(mani, null, this.getClass().getClassLoader());

        try {
            mgr.enable(new HashSet<Module>(Arrays.asList(toFail, fixed)));
            fail("Was able to turn on fails-on-non-existing-package.jar without complaint");
        } catch (InvalidException e) {
            assertTrue("fails-on-non-existing-package.jar was not enabled", e.getModule() == toFail);
        }

        assertTrue("simple-module.jar was enabled", fixed.isEnabled());
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:ModuleManagerTest.java

示例9: jarFileOf

import java.util.jar.JarFile; //导入方法依赖的package包/类
@Test
public void jarFileOf() throws IOException {
    JarFile jf = Classes.jarFileOf(Logger.class);
    assertNotNull(jf);
    Manifest mf = jf.getManifest();
    Attributes attrs = mf.getMainAttributes();
    String name = attrs.getValue("Bundle-Name");
    String version = attrs.getValue("Bundle-Version");
    if (VERBOSE) {
        System.out.println(name);
        System.out.println(version);
    }
    assertNotNull(name);
    assertNotNull(version);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:ClassesTest.java

示例10: isOSGiBundle

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static boolean isOSGiBundle(File jarFile) {
    try {
        JarFile jar = new JarFile(jarFile);
        Manifest mf = jar.getManifest();
        return mf != null && mf.getMainAttributes().getValue("Bundle-SymbolicName") != null; // NOI18N
    } catch (IOException ioe) {
        ERR.log(Level.INFO, ioe.getLocalizedMessage(), ioe);
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:AutoupdateInfoParser.java

示例11: getJarManifestClasspath

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static List<String> getJarManifestClasspath(String path)
    throws Exception {
  List<String> classpath = new ArrayList<String>();
  JarFile jarFile = new JarFile(path);
  Manifest manifest = jarFile.getManifest();
  String cps = manifest.getMainAttributes().getValue("Class-Path");
  StringTokenizer cptok = new StringTokenizer(cps);
  while (cptok.hasMoreTokens()) {
    String cpentry = cptok.nextToken();
    classpath.add(cpentry);
  }
  return classpath;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:TestContainerLaunch.java

示例12: addJarClassPath

import java.util.jar.JarFile; //导入方法依赖的package包/类
private void addJarClassPath(String jarFileName, boolean warn) {
            try {
                String jarParent = new File(jarFileName).getParent();
                JarFile jar = new JarFile(jarFileName);

                try {
                    Manifest man = jar.getManifest();
                    if (man == null) return;

                    Attributes attr = man.getMainAttributes();
                    if (attr == null) return;

                    String path = attr.getValue(Attributes.Name.CLASS_PATH);
                    if (path == null) return;

                    for (StringTokenizer st = new StringTokenizer(path);
                        st.hasMoreTokens();) {
                        String elt = st.nextToken();
                        if (jarParent != null)
                            elt = new File(jarParent, elt).getCanonicalPath();
                        addFile(elt, warn);
                    }
                } finally {
                    jar.close();
                }
            } catch (IOException e) {
//              log.error(Position.NOPOS,
//                        "error.reading.file", jarFileName,
//                        e.getLocalizedMessage());
            }
        }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:BatchEnvironment.java

示例13: safeGetClassPath

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static String safeGetClassPath(final JarFile jar) throws IOException {
    final Manifest mf = jar.getManifest();
    if (mf != null && mf.getMainAttributes() != null) {
        return mf.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
    }
    return null;
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:8,代码来源:ClassLoaderAnalyzer.java

示例14: openTemplate

import java.util.jar.JarFile; //导入方法依赖的package包/类
public void openTemplate() {
	if (Defaults.getAsBoolean("showTemplateDialog")) {
		JOptionPane.showMessageDialog(parent, "Each template has some default values for the parameters. "
					+ "Once instantiated you may change them according to your needs.");
		Defaults.set("showTemplateDialog", "false");
		Defaults.save();
	}

	int selectedRow = templateTable.getSelectedRow();
	if (selectedRow != -1 && templateTable.getRowCount() != 0) {
		// close the template panel dialog
		SwingUtilities.getWindowAncestor(parent).setVisible(false);
		try {
			File template = templates[selectedRow].getFile();
			File copy = File.createTempFile(template.getName(), "");
			FileUtils.copyFile(templates[selectedRow].getFile(), copy);
			JarFile templateJarFile = new JarFile(copy);

			// get the path of template
			Manifest m = templateJarFile.getManifest();
			String mainClass = m.getMainAttributes().getValue("Main-Class").toString();

			URL url = new URL("file:" + copy.getAbsolutePath());
			URLClassLoader myLoader = new URLClassLoader(new URL[] { url }, Thread.currentThread().getContextClassLoader());
			Class<?> myClass = myLoader.loadClass(mainClass);

			// instantiate the template
			myTemp = (ITemplate) myClass.getConstructor(mediator.getClass()).newInstance(mediator);
			// shows the input panel of the template
			myTemp.showDialog(mediator.getMainWindow());

			templateJarFile.close();
			myLoader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:39,代码来源:TemplatePanel.java

示例15: readManifest

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static String readManifest(File file, String attr) throws IOException {
	String value = null;
	JarFile templateJarFile = new JarFile(file);
	Manifest m = templateJarFile.getManifest();
	value = m.getMainAttributes().getValue(attr).toString();
	templateJarFile.close();
	return value;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:9,代码来源:TemplateFileOperation.java


注:本文中的java.util.jar.JarFile.getManifest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。