2011-11-02 119 views
3

我們正在開發一個相當大的項目,並有許多依賴項。最近,我們遇到了兩個人之間的衝突問題,agileAPI.jar和axis.jar。這兩個都是第三方庫。Java - 如何獲得依賴關係以忽略對方?

問題代碼直接取決於agileAPI.jar。如果我在構建路徑中構建它,那麼依賴它的所有東西都能正常工作。

只要我將axis.jar添加到構建路徑(只是添加它,而不是編寫依賴它的代碼),一切都會出錯。一些依賴於第一個庫的代碼現在拋出第二個庫的異常。這就好像第一個圖書館正在挑選和選擇從第二個圖書館打電話的方法,而不是從以前的電話中調用它們。

我在需要axis.jar的項目中直接使用代碼,所以我不能將它從構建路徑中刪除。我需要找到一種方法讓這兩個存在於相同的構建路徑中,但忽略對方。

應該注意的是,兩個庫在最近升級之前與敏捷兼容。我一直在與Oracle的支持團隊合作,嘗試解決這個問題。但是,兩週後,我正在尋找其他的幫助來源。

我們的環境是Windows和Eclipse,雖然在測試時,它也會在從命令行運行java時發生。我們的JDK是1.5.0_22。

任何幫助,將不勝感激。

謝謝

大衛

編輯:

按照要求,這裏有我們所看到的堆棧跟蹤。第一個堆棧跟蹤打印在代碼超出了我的控制:異常堆滿了

java.lang.NoSuchMethodError: org.apache.axis.description.OperationDesc.setStyle(Lorg/apache/axis/constants/Style;)V 
    at com.agile.webfs.components.fileserver.client.FileServerSoapBindingStub._initOperationDesc1(FileServerSoapBindingStub.java:37) 
    at com.agile.webfs.components.fileserver.client.FileServerSoapBindingStub.<clinit>(FileServerSoapBindingStub.java:20) 
    at com.agile.webfs.components.fileserver.client.FileServerWSServiceLocator.getFileServer(FileServerWSServiceLocator.java:43) 
    at com.agile.webfs.client.IFSLocator.getRemoteFileServer(IFSLocator.java:128) 
    at com.agile.webfs.client.IFSLocator.getConnection(IFSLocator.java:101) 
    at com.agile.api.pc.EJBLookup.createFileSession(EJBLookup.java:444) 
    at com.agile.api.pc.EJBLookup.getFileSession(EJBLookup.java:432) 
    at com.agile.api.pc.attachment.IFSOutputStream.getFileSession(IFSOutputStream.java:133) 
    at com.agile.api.pc.attachment.IFSOutputStream.copyFrom(IFSOutputStream.java:87) 
    at com.agile.api.pc.attachment.IFSOutputStream.copyFrom(IFSOutputStream.java:115) 
    at com.agile.api.pc.TableAttachment.uploadFile(TableAttachment.java:886) 
    at com.agile.api.pc.TableAttachment$AddFiles2Action.doSdkAction(TableAttachment.java:724) 
    at com.agile.api.common.SDKAction.run(SDKAction.java:23) 
    at com.agile.api.common.OracleAuthenticator.doAs(OracleAuthenticator.java:131) 
    at com.agile.api.common.Security.doAs(Security.java:54) 
    at com.agile.api.common.Security.doAs(Security.java:109) 
    at com.agile.api.pc.TableAttachment.addFiles2(TableAttachment.java:483) 
    at com.agile.api.pc.TableAttachment.createNewBlob2(TableAttachment.java:459) 
    at com.agile.api.pc.TableAttachment.doCreateServerRowWithParam(TableAttachment.java:363) 
    at com.agile.api.pc.Table.createTableRow(Table.java:238) 
    at com.agile.api.pc.TableAttachment.createTableRow(TableAttachment.java:169) 
    at com.agile.api.pc.Table.createRow(Table.java:202) 
    at com.[snip].updateAttachments(VaultImportService.java:3068) 
    at com.[snip].processIncorporatedFile(VaultImportService.java:926) 
    at com.[snip].processPdxFile(VaultImportService.java:532) 
    at com.[snip].processPdxRequest(VaultImportService.java:388) 
    at com.[snip].<init>(VaultImportService.java:299) 
    at com.[snip].main(VaultImportService.java:3660) 

後,我們抓住它,我們打印堆棧跟蹤的樣子:

at com.agile.api.pc.Session.createError(Session.java:1772) 
at com.agile.api.pc.EJBLookup.createFileSession(EJBLookup.java:454) 
at com.agile.api.pc.EJBLookup.getFileSession(EJBLookup.java:432) 
at com.agile.api.pc.attachment.IFSOutputStream.getFileSession(IFSOutputStream.java:133) 
at com.agile.api.pc.attachment.IFSOutputStream.copyFrom(IFSOutputStream.java:87) 
at com.agile.api.pc.attachment.IFSOutputStream.copyFrom(IFSOutputStream.java:115) 
at com.agile.api.pc.TableAttachment.uploadFile(TableAttachment.java:886) 
at com.agile.api.pc.TableAttachment$AddFiles2Action.doSdkAction(TableAttachment.java:724) 
at com.agile.api.common.SDKAction.run(SDKAction.java:23) 
at com.agile.api.common.OracleAuthenticator.doAs(OracleAuthenticator.java:131) 
at com.agile.api.common.Security.doAs(Security.java:54) 
at com.agile.api.common.Security.doAs(Security.java:109) 
at com.agile.api.pc.TableAttachment.addFiles2(TableAttachment.java:483) 
at com.agile.api.pc.TableAttachment.createNewBlob2(TableAttachment.java:459) 
at com.agile.api.pc.TableAttachment.doCreateServerRowWithParam(TableAttachment.java:363) 
at com.agile.api.pc.Table.createTableRow(Table.java:238) 
at com.agile.api.pc.TableAttachment.createTableRow(TableAttachment.java:169) 
at com.agile.api.pc.Table.createRow(Table.java:202) 
at com.[snip].updateAttachments(VaultImportService.java:3068) 
at com.[snip].processIncorporatedFile(VaultImportService.java:926) 
at com.[snip].processPdxFile(VaultImportService.java:532) 
at com.[snip].processPdxRequest(VaultImportService.java:388) 
at com.[snip].<init>(VaultImportService.java:299) 
at com.[snip].main(VaultImportService.java:3660) 

在這兩種情況下,行「在com.agile.api.pc.Table.createRow(Table.java:202)」是我正在做的agileAPI調用。我已經刪除了我們的包裝結構,因爲它標識了我工作的公司。他們重視隱私和安全。

+0

哪個版本的軸是那個jar文件? –

+0

這些庫之間是否存在名稱衝突?我猜Oracle已經提出了這個建議,但是你可以在你的代碼中明確表示(例如,當聲明變量時,把它們的全部名稱放在它們前面,比如'com.package.Foo foo = new Foo(); '? – jefflunt

+1

您是否嘗試更改類路徑中的順序?如果運氣好的話,它將起作用。無論如何,您能否提供有關錯誤消息和此庫的起源的更多詳細信息。 – PeterMmm

回答

1

我建議你先檢查一下這兩個東西:

  • 打開一些壓縮軟件的axis.jar文件,像7-Zip或WinRAR的。查看jar中META-INF文件夾中是否有名爲「services」的文件夾。如果有的話,axis.jar文件可能會指定某種特定接口的實現,它們不會與agileAPI進行交互操作。對於agileAPI.jar也要這樣做,因爲它可能會聲明一個axis不喜歡的接口實現。
  • 用zip實用程序打開agileAPI.jar和axis.jar,然後檢查是否存在具有相同名稱的包。如果沒有,它不會是一個命名衝突。如果有一個或多個,請打開相應的文件夾並遞歸執行相同的檢查。如果最終在兩個罐子的同一個包中至少有一個具有相同名稱的類,則可能是命名衝突。

這應該抓住最明顯的問題。如果沒有這種情況,我們需要更深入地觀察。

+0

很抱歉,有很多文件需要通過,jar文件在元文件夾中都沒有服務文件夾,也沒有manafest也指定了任何重要的東西。 在兩個文件之間,它們共享7個具有相同名稱的類。但是,它們位於不同的文件夾中。我的首選環境是.Net,所以我對Java和軟件包有些陌生,但我相信這意味着它們在不同的軟件包中? 此外,這兩個文件的開始文件夾結構不同。 axis.jar中的所有類都在org/apache/axis中開始...並且AgileAPI.jar從com/agile/...開始 – Eckish

+0

@Eckish所以我想下一個最可能的問題是命名衝突,像其他人一樣。查看是否可以在同一個包路徑中找到具有相同名稱的類。 –

+0

對,對不起。我是Stack overflow的新手。我試圖開始一個新的段落,並最終提前提交。 – Eckish

0

解決此類路徑問題的一種方法是使用模塊系統,如OSGi或NetBeans平臺模塊系統,其中每個模塊都有自己的類加載器。