【问题标题】:Get the versions of jars,ears and wars and read them programatically in Weblogic server and Glassfish server获取 jars、ears 和 wars 的版本,并在 Weblogic 服务器和 Glassfish 服务器中以编程方式阅读它们
【发布时间】:2014-08-11 02:16:15
【问题描述】:

我的客户想要获取 web-logic server/glassfish server 的所有已部署模块(jar、war 和 ear)的版本。

客户需要一个 UI,他们需要在其中查看所有 jar 的列表及其版本。他们将使用 weblogic 和 glassfish 服务器。

是否有任何行业惯例对 jar 进行版本控制和监控?

我尝试过的方法:

  1. 在创建 jar 时,我已包含 Manifest.MF 文件,其中包含 Implementation-Version(键)和版本号(值)。

  2. 通过 java weblogic 部署 API,我可以获得已部署模块的名称列表(如 ear、war 等),但我无法获取每个已部署模块的内容。

  3. 同样,我必须编写用于在 glassfish 服务器中读取的代码

【问题讨论】:

    标签: glassfish weblogic manifest.mf


    【解决方案1】:

    您可以使用 Java 和 JMX 在 weblogic 中列出所有已部署的应用程序和版本信息,如下所示:

    private static final String RUNTIME_MBEAN_SERVER_JNDI_NAME 
       = "java:comp/env/jmx/runtime";
    ...
    private static MBeanServer getMBeanServer() {
    MBeanServer mBeanServer = null;
    
    try {
        InitialContext initialContext = new InitialContext();
        mBeanServer = 
               (MBeanServer) initialContext.lookup(RUNTIME_MBEAN_SERVER_JNDI_NAME);
    } catch (NamingException e) {
        LOGGER.error("Error connecting to the MBean server", e);
    }
    
      return mBeanServer;
    }
    

    public static Map<String, String> getDeployedApplications() {
    Map<String, String> deployedApplications = 
           new HashMap<String, String>();
    
    try {
        MBeanServer mBeanServer = getMBeanServer();
        ObjectName domainConfiguration =
               (ObjectName) mBeanServer.getAttribute(
                      new ObjectName(RuntimeServiceMBean.OBJECT_NAME), 
                      "DomainConfiguration");
        ObjectName[] appDeployments = 
               (ObjectName[]) mBeanServer.getAttribute(
                      domainConfiguration, 
                      "AppDeployments");
        for (ObjectName appDeployment : appDeployments) {
            try {
                Object applicationName = 
                       mBeanServer.getAttribute(
                              appDeployment, 
                              "ApplicationName");
                Object versionIdentifier = 
                       mBeanServer.getAttribute(
                              appDeployment, 
                              "VersionIdentifier");
                if (versionIdentifier != null) {
                    deployedApplications.put(
                           applicationName.toString(), 
                           versionIdentifier.toString());
                }
            } catch (Exception e) {
                LOGGER.error(String.format("Error fetching deploy info for '%s'", 
                       appDeployment), e);
            }
        }
      } catch (Exception e) {
        LOGGER.error("Error fetching deployed applications", e);
      }
    
       return Collections.unmodifiableMap(deployedApplications);
    }
    

    有关应用程序运行时的 Oracle API here

    在 JMX 部署文档here中查看更多属性

    还有上面的例子here

    【讨论】:

    • 感谢您提出这种方法。我可以获得耳朵和战争的版本,但这里的主要问题是我需要打印耳朵和战争内部的罐子的版本。我无法根据名称在应用服务器中加载ear和war的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多