2014-01-24 139 views
-2

在jboss 4中,我們使用了dom4j SAX解析器來讀取server.xml。它工作正常,但它不是在JBoss的EAP 6。下面的情況下,工作在JBoss的4更改JBoss EAP 6端口號

public static Document modifyAttributeValue(Document document, String elementName, String attributeName, String attributeValue) { 
    if (document == null) 
     return document; 
    try { 
     Element element = (Element) document.selectSingleNode(elementName); 
     if (element != null) { 
      Attribute attribute = element.attribute(attributeName); 
      attribute.setValue(attributeValue); 
     } 
    } catch (Exception e) { 
     logger.error("Failed to modify attribute.", e); 
    } 
    return document; 
} 

我得到元素作爲空值使用的代碼。

+0

因此,無論您嘗試選擇哪個元素都不在該文件中,並且可能已移至其他文件。通過實際執行研究來修復它。 – Gimby

+0

我正在使用此代碼獲取節點 – Rajesh

+0

modifyAttributeValue(document,「// socketbinding [@ name ='http']」,「port」,「8080」); – Rajesh

回答

2

拉傑什,

正如EIS剛纔指出,JBoss的EAP 6.x的是基於在JBoss AS 7.x的代碼的基礎上,其比早期版本顯著不同(的JBoss AS 4.x中,5.x的,6.x,JBoss EAP 5.x)

端口在server.xml中沒有像以前的版本那樣定義,而是在JBOSS_HOME/standalone/configuration/standalone.xml中定義。

嘗試使用Eclipse(或您最喜歡的IDE)調試您的代碼,放置很少的斷點並逐行執行代碼。看看爲什麼你得到NULL,我的猜測是你的文檔通過了NULL,因此你的modifyAttributeValue()方法也返回NULL

現在,如果您希望以編程方式更改端口,那麼執行此操作的方法很少。

最簡單的是使用JBoss CLI(本地接口):

JBOSS_HOME/bin/jboss-cli.sh --connect 

/socket-binding-group=standard-sockets/socket-binding=http:write-attribute(name=port,value=8081) 

希望有所幫助。