从一个项目中的不同 Salesforce SOAP jar 调用 API
Call APIs from different Salesforce SOAP jars in one project
我正在使用 Salesforce SOAP 开展一个项目 API。我需要为我的项目中的不同 Salesforce 实例使用来自不同 SOAP API jar 的 java classes,但是 classes 名称和它们的包名称完全相同.
例如:
Salesforce 实例 A 的 jar 有 com.sforce.soap.enterprise.sobject.SObject.Opportunity,它有一个名为 attrA;
Salesforce 实例 B 的 jar 有 com.sforce.soap.enterprise.sobject.SObject.Opportunity,它有一个名为 attrB;
Maven 结构:
如何在我的单个项目中同时使用 attrA 和 attrB?也就是说,同包名和class名称不同的class如何区分呢?
我是否必须将我的项目拆分为两个子项目才能使用这两个 jar?
您不能在 Java 中执行此操作。包名称 + class 名称对于项目必须是唯一的。
您可能需要重构您的项目,使不同的 Salesforce JAR 位于它们自己的项目中,并且只向您的主项目公开必要的接口。唯一的其他选择是编写自定义 class 加载程序,但这相当复杂。
查看 package documentation here:
Developers should take steps to avoid the possibility of two published packages having the same name by choosing unique package names for packages that are widely distributed. This allows packages to be easily and automatically installed and catalogued. This section specifies a suggested convention for generating such unique package names. Implementations of the Java platform are encouraged to provide automatic support for converting a set of packages from local and casual package names to the unique name format described here.
If unique package names are not used, then package name conflicts may arise far from the point of creation of either of the conflicting packages. This may create a situation that is difficult or impossible for the user or programmer to resolve. The class ClassLoader can be used to isolate packages with the same name from each other in those cases where the packages will have constrained interactions, but not in a way that is transparent to a naïve program.
我正在使用 Salesforce SOAP 开展一个项目 API。我需要为我的项目中的不同 Salesforce 实例使用来自不同 SOAP API jar 的 java classes,但是 classes 名称和它们的包名称完全相同.
例如:
Salesforce 实例 A 的 jar 有 com.sforce.soap.enterprise.sobject.SObject.Opportunity,它有一个名为 attrA;
Salesforce 实例 B 的 jar 有 com.sforce.soap.enterprise.sobject.SObject.Opportunity,它有一个名为 attrB;
Maven 结构:
如何在我的单个项目中同时使用 attrA 和 attrB?也就是说,同包名和class名称不同的class如何区分呢?
我是否必须将我的项目拆分为两个子项目才能使用这两个 jar?
您不能在 Java 中执行此操作。包名称 + class 名称对于项目必须是唯一的。
您可能需要重构您的项目,使不同的 Salesforce JAR 位于它们自己的项目中,并且只向您的主项目公开必要的接口。唯一的其他选择是编写自定义 class 加载程序,但这相当复杂。
查看 package documentation here:
Developers should take steps to avoid the possibility of two published packages having the same name by choosing unique package names for packages that are widely distributed. This allows packages to be easily and automatically installed and catalogued. This section specifies a suggested convention for generating such unique package names. Implementations of the Java platform are encouraged to provide automatic support for converting a set of packages from local and casual package names to the unique name format described here.
If unique package names are not used, then package name conflicts may arise far from the point of creation of either of the conflicting packages. This may create a situation that is difficult or impossible for the user or programmer to resolve. The class ClassLoader can be used to isolate packages with the same name from each other in those cases where the packages will have constrained interactions, but not in a way that is transparent to a naïve program.