cloudsoft / winrm4j

Apache License 2.0
94 stars 53 forks source link

winrm4j 0.4.0, unsatisfied dependencies at runtime using maven #77

Open vitovex opened 6 years ago

vitovex commented 6 years ago

I've created a very simple Maven CLI application in Java 8, adding this dependency:

<dependency>
    <groupId>io.cloudsoft.windows</groupId>
    <artifactId>winrm4j</artifactId>
    <version>0.5.0</version>
</dependency>

It contains this code:

String h = "10.10.10.10";
String s = "Showroom_K2";
String u = "adminuser"; 
String p = "password";

WinRmClientContext context = WinRmClientContext.newInstance();
WinRmTool.Builder builder = WinRmTool.Builder.builder(h, u, p);
builder.setAuthenticationScheme(AuthSchemes.NTLM );     
builder.port(5985);         
builder.useHttps(false);        
//builder.disableCertificateChecks(true);       
builder.context(context);       
WinRmTool tool =  builder.build();              
List<String> cmds = new ArrayList<>();      
cmds.add("$processes = Get-WmiObject Win32_Process -Filter \"name = 'java.exe' and commandline like '%SERVICES eq " + s +  "%'\"");         
cmds.add("$processes.Path");        
WinRmToolResponse response = tool.executePs(cmds);

If I execute this code from Eclipse, I get this error on the last instruction:

dic 15, 2017 6:04:46 PM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd}WinRmService from WSDL: jar:file:/C:/Users/vve/.m2/repository/io/cloudsoft/windows/winrm4j-client/0.5.0/winrm4j-client-0.5.0.jar!/wsdl/WinRmService.wsdl
Exception in thread "main" java.lang.NoSuchFieldError: REFLECTION
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:93)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:473)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:319)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1170)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:344)
    at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:342)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:342)
    at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:243)
    at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:472)
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:327)
    at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:425)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:527)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:262)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:199)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
    at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:93)
    at io.cloudsoft.winrm4j.client.WinRmClient.doCreateServiceWithBean_Part1(WinRmClient.java:622)
    at io.cloudsoft.winrm4j.client.WinRmClient.doCreateServiceWithBean(WinRmClient.java:611)
    at io.cloudsoft.winrm4j.client.WinRmClient.createService(WinRmClient.java:518)
    at io.cloudsoft.winrm4j.client.WinRmClient.getService(WinRmClient.java:502)
    at io.cloudsoft.winrm4j.client.WinRmClient.command(WinRmClient.java:316)
    at io.cloudsoft.winrm4j.winrm.WinRmTool.executeCommand(WinRmTool.java:243)
    at io.cloudsoft.winrm4j.winrm.WinRmTool.executePs(WinRmTool.java:269)
    at com.klopotek.core.liveaid.LiveAidCLI.main(LiveAidCLI.java:99)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [util.c:840]

But, if a build the application via maven (mvn clean install), I get this error on the same instruction:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/ws/soap/SOAPFaultException
            at io.cloudsoft.winrm4j.winrm.WinRmTool.executeCommand(WinRmTool.java:210)
            at io.cloudsoft.winrm4j.winrm.WinRmTool.executePs(WinRmTool.java:269)
            at com.klopotek.core.liveaid.LiveAidCLI.main(LiveAidCLI.java:99)
    Caused by: java.lang.ClassNotFoundException: javax.xml.ws.soap.SOAPFaultException
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
            at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
            ... 3 more

If I add lots of dependencies related to javax, cxf, etc, I am finally able to execute it properly, but only inside Eclipse. What is wrong with this approach? Is the dependency maven winrm4j self consistent?