在安装vcenter 7.0之前,一直在使用vijava,作为java操作vcenter资源的SDK,但是升级到vcenter7.0之后,这些API无法使用了,程序会报错:
# 代码实例
@Test
public void getVmrc() throws MalformedURLException, RemoteException {
String vcId = "VirtualMachine-101";
Vcenter vcenter = getVcenter7();
BsipVmFactory bsipVmFactory = new BsipVmFactory("https://" + vcenter.getIp() + "/sdk", vcenter.getUser(), vcenter.getPassword());
String acquireCloneTicket = bsipVmFactory.getSi()
.getSessionManager().acquireCloneTicket();
System.out.println(String.format("vmrc://clone:%s@%s/?moid=%s",
acquireCloneTicket, vcenter.getIp(), vcId.split("VirtualMachine-")[1]));
}
# 报错信息
java.rmi.RemoteException: VI SDK invoke exception:java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: Error on line 1 of document : 前言中不允许有内容。 Nested exception: 前言中不允许有内容。
at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:122)
at com.vmware.vim25.ws.VimStub.retrieveServiceContent(VimStub.java:1433)
at com.vmware.vim25.mo.ServiceInstance.<init>(ServiceInstance.java:85)
at com.vmware.vim25.mo.ServiceInstance.<init>(ServiceInstance.java:69)
at bsip.vmware.vim25.BsipVmFactory.<init>(BsipVmFactory.java:51)
at InstanceTest.getVmrc(InstanceTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
在vcenter官方网站上,对vcenter7.0有这么一段描述:
总而言之就是,在vcenter 7.0中,vijava是用不了的,好在有一个vijava的fork版本,yavijava。
官方地址:https://github.com/yavijava/yavijava
基本上yavijava可以无缝支持vijava的功能,切换只需要更换maven对jar包的引用,maven仓库地址:https://mvnrepository.com/artifact/com.toastcoders/yavijava/6.0.05
.最新版本未6.0.05.
jar包下载地址为:https://repo1.maven.org/maven2/com/toastcoders/yavijava/6.0.05/yavijava-6.0.05.jar
,下载后,安装到本地仓库中:
mvn install:install-file -Dfile=Downloads/yavijava-6.0.05.jar -DgroupId=com.toastcoders -DartifactId=yavijava -Dversion=6.0.05 -Dpackaging=jar
修改maven配置,删除掉旧的vijava的jar包引用,使用yavijava:
<dependency>
<groupId>com.toastcoders</groupId>
<artifactId>yavijava</artifactId>
<version>6.0.05</version>
</dependency>
再次尝试单元测试,脚本调用成功。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。