如何从Web应用程序中存在的类访问Ear的清单文件? [英] How to access ear's Manifest file from the class present in web app?

查看:133
本文介绍了如何从Web应用程序中存在的类访问Ear的清单文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从位于耳朵内的Web应用程序中存在的类访问EAR清单文件中定义的属性.有什么办法可以访问它.当前,我通过传递属性名称/值来使用以下代码,以访问正确的清单文件,然后我将添加更多代码以获取所需属性的值.

I want to access a property defined in an EAR's manifest file from a class which is present in the web app positioned within the ear. Is there any way to access that. Currently, I am using the following code by passing a property name/value to access the correct manifest file and then I will add more code to get the value for my desired property.

public static Manifest getManifest(Class<?> cls, String entryName, String entryValue) throws IOException
{
    Manifest retManifest = null;
    boolean matchFound = false;
    Class<?> srcClass = cls == null ? this.class : cls;
    Enumeration<URL> resources = srcClass.getClassLoader().getResources("META-INF/MANIFEST.MF");

    while (resources.hasMoreElements() && matchFound == false)
    {
        URL u = resources.nextElement();
        Manifest manifest = new Manifest(u.openStream());
        if (manifest != null)
        {
            Attributes atr = manifest.getMainAttributes();
            if (atr != null && atr.keySet() != null)
            {
                Iterator<Object> atrIr = atr.keySet().iterator();
                while (atrIr.hasNext() && matchFound == false)
                {
                    Object atrKey = atrIr.next();
                    if (atrKey != null && atrKey.toString().equals(entryName))
                    {
                        if (atr.get(atrKey) != null && atr.get(atrKey).toString().equals(entryValue))
                        {
                            retManifest = manifest;
                            matchFound = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    return retManifest;
}

我的问题是代码可以正常运行并扫描来自各个jar文件的所有清单,但以某种方式找不到在耳朵的META-INF文件夹下存在的清单文件.有人可以帮我找到同样的东西.

My problem is that code is running fine and scans all manifests from various jar files but it somehow donot find the Manifest file present under ear's META-INF folder. Can somebody help me in finding the same.

推荐答案

请参见 EAR文件格式Wiki

============== >>>> META-INF目录至少包含application.xml部署描述符,称为Java EE部署描述符.它包含以下XML实体:

==============>>>> The META-INF directory contains at least the application.xml deployment descriptor, known as the Java EE Deployment Descriptor. It contains the following XML entities:

图标,用于指定代表应用程序的图像的位置.对小图标和大图标进行了细分. 显示名称,用于标识应用程序 描述 归档中每个模块的模块元素 应用程序中全局安全角色的零个或多个安全角色元素 每个模块元素都包含一个ejb,web或java元素,它们描述了应用程序中的各个模块. Web模块还提供了一个上下文根,可以通过其URL标识Web模块.

icon, which specifies the locations for the images that represent the application. A subdivision is made for small-icon and large-icon. display-name, which identifies the application description A module element for each module in the archive Zero or more security-role elements for the global security roles in the application Each module element contains an ejb, web or java element which describes the individual modules within the application. Web modules also provide a context-root which identifies the web module by its URL.

程序中正在查看的耳朵的META-INF目录中没有MANIFEST.MF.

There's no MANIFEST.MF in ear's META-INF directory that is being looked upon in the program.

这篇关于如何从Web应用程序中存在的类访问Ear的清单文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆