本文整理汇总了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;
}
}
示例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();
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
}
}
示例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);
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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();
}
}
}
示例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;
}