2016-04-20 9 views
0

おやすみなさい。 私は= がhttps://community.oracle.com/blogs/serli/2010/08/30/how-use-glassfish-application-versioningglassfish/javaeeアプリケーションのバージョンを取得するには?

$のasadmin --nameを展開中と、テストバージョンでいくつかのテスト・アプリケーションをデプロイ:BETA-1.1 test.war

をしかし、私は、アプリケーション名 http://javahowto.blogspot.ru/2009/12/how-to-get-module-name-and-app-name.html

を取得しようとすると、 initialContext.lookup( "java:app/AppName") - バージョンなしで返されました。 アプリケーションのバージョンをプログラムで取得することは可能ですか?私はそれがAppNameはを取得するソースの場所を見つけたバージョン

+0

これはあなたの質問をカバーしていますか?http://blog.payara.fish/deploying-multiple-application-versions-on-payara-server? (PayaraはGlassfishをベースにしています)。 – simdevmon

+0

simdevmonは、マルチバージョン展開を示しています。現在のアプリケーションのバージョンを取得する方法については言及していません。 – lunicon

答えて

0

付きリスト・アプリケーション プリントのappplication名のasadmin

$:!

glassfish3 \ GlassFishの\モジュール\コンテナ-common.jarをCOM /日/ createApplication

に設定された企業/容器/共通/ IMPL/ JavaModuleNamingProxyの.class

private String getAppName() throws NamingException { 
    ComponentEnvManager namingMgr = (ComponentEnvManager)this.habitat.getComponent(ComponentEnvManager.class); 

    String appName = null; 
    if (namingMgr != null) { 
     JndiNameEnvironment env = namingMgr.getCurrentJndiNameEnvironment(); 

     BundleDescriptor bd = null; 
     if ((env instanceof EjbDescriptor)) { 
     bd = ((EjbDescriptor)env).getEjbBundleDescriptor(); 
     } else if ((env instanceof BundleDescriptor)) { 
     bd = (BundleDescriptor)env; 
     } 
     if (bd != null) { 
     Application app = bd.getApplication(); 
     appName = app.getAppName(); // <-- HERE! 
     } 
    } 
    if (appName == null) 
     throw new NamingException("Could not resolve java:app/AppName"); 

    return appName; 
    } 

とApplication.getAppName()

glassfish3 \ GlassFishの\モジュール\ dol.jar!COM /日/企業/展開/ アプリケーションの.class

public static Application createApplication(Habitat habitat, String name, ModuleDescriptor <BundleDescriptor> newModule) { 
    Application application = new Application(habitat); 
    application.setVirtual(true); 
    if ((name == null) && (newModule.getDescriptor() != null)) { 
     name = ((BundleDescriptor)newModule.getDescriptor()).getDisplayName(); 
    } 
    String untaggedName = VersioningUtils.getUntaggedName(name); 
    if (name != null) { 
     application.setDisplayName(untaggedName); 
     application.setName(untaggedName); 
     application.setAppName(untaggedName); 
    } 
    newModule.setStandalone(true); 
    newModule.setArchiveUri(untaggedName); 
    if (newModule.getDescriptor() != null) { 
     ((BundleDescriptor)newModule.getDescriptor()).setApplication(application); 
    } 
    application.addModule(newModule); 
    return application; 
    } 

あなたはそれがアプリケーション内でタグ付けされた名前を保存doesntの見ることができるように。なぜdisplayNameを使用しないのですか?それでも 、私はバージョン情報を取得するための別の方法を見つけてみますが... GlassFishの-application.xmlの/バージョン識別子を読む/設定することができる

更新:のglassfishは、バージョンのフォルダを作成します(ドメイン|ノード) /アプリケーション/ appName〜バージョン。だから我々はいくつかのリソースのパスを分析することができます:)

static final Pattern APP_VER = Pattern.compile("/applications/([^~/]+)(?:~([^/]*))?"); 

public String getAppVersion() { 
    URL res = getClass().getResource("/META-INF/somefile.xml"); 
    if (res != null) { 
    Matcher ver = APP_VER.matcher(res.getPath()); 
    if (ver.find()) 
     return ver.group(2); 
    } 

    return null; 
} 

楽しんでください!たぶん誰かがもっと美しい解決策を持っているでしょうか

関連する問題