Milo OPC-UA 客户端 NoSuchMethod 错误 io.netty.buffer.ByteBuf.writeMediumLE(int)

Milo OPC-UA Client NoSuchMethod error with io.netty.buffer.ByteBuf.writeMediumLE(int)

我从 GitHub 下载了示例代码并修改了 ReadNodeExample.java 以确保我可以连接到 OPC 服务器(不是 Milo,它是基于 C# 的 OPC 服务器)。我能够验证示例代码能够通过修改从我的服务器 read/write/call 节点。

然后我将我认为我需要的东西重新实现到我的实际项目中,但是我可能遗漏了一些东西,因为我无法在这个项目下连接并收到以下错误:

java.lang.NoSuchMethodError: 'io.netty.buffer.ByteBuf io.netty.buffer.ByteBuf.writeMediumLE(int)'

此错误发生在 ClientExampleRunner.run() 而 运行ning createClient() 我仍然可以 运行 示例项目并且仍然可以连接。

这是我的 pom.xml: org.milo 添加在接近尾声的位置,我添加了我从示例中看到的内容(包括 ch.qos.logback 和 jetbrains)。然后添加了io.netty以为会有帮助,但仍然有同样的错误。

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.companyname</groupId>
    <artifactId>companyname-backend-final</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>companyname-backend-final</name>

    <build>
        <finalName>jerseyJetty</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!-- make the jar file -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>

                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>package org.companyname_backend_final.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>4.0.3</version>
            </plugin>

        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>


        </dependencies>


    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
            <!--artifactId>jersey-container-servlet</artifactId -->
        </dependency>
        <!--<dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> 
            <version>3.30.1</version> </dependency> -->
        <!-- https://mvnrepository.com/artifact/io.github.willena/sqlite-jdbc -->
        <dependency>
            <groupId>io.github.willena</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.31.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.json/json -->
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>

        <!-- embedded jetty -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-jetty-http</artifactId>

        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>9.4.0.v20161208</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>9.4.0.v20161208</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>9.4.0.v20161208</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.moxy</artifactId>
            <version>2.6.0</version>
        </dependency>
        
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
        </dependency>

        <!-- netty websocket -->
        <dependency>
            <groupId>com.corundumstudio.socketio</groupId>
            <artifactId>netty-socketio</artifactId>
            <version>1.7.7</version>
        </dependency>


        <!-- netty http -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-netty-http</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mindrot/jbcrypt -->
        <dependency>
            <groupId>org.mindrot</groupId>
            <artifactId>jbcrypt</artifactId>
            <version>0.4</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-nop</artifactId>
            <version>1.7.26</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.19.4</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.19.4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>6.2.1</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6.12</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-multipart</artifactId>
            <version>1.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit -->
        <dependency>
            <groupId>org.eclipse.jgit</groupId>
            <artifactId>org.eclipse.jgit</artifactId>
            <version>5.8.1.202007141445-r</version>
        </dependency>
        <dependency>
            <groupId>com.digitalpetri.netty</groupId>
            <artifactId>netty-channel-fsm</artifactId>
            <version>0.5</version>
            <exclusions>
                <exclusion>
                    <groupId>com.digitalpetri.fsm</groupId>
                    <artifactId>strict-machine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-codec-http</artifactId>
            <version>4.1.70.Final</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>sdk-client</artifactId>
            <version>0.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>dictionary-reader</artifactId>
            <version>0.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>server-examples</artifactId>
            <version>0.6.4</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.7</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>22.0.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <properties>
        <jersey.version>2.26</jersey.version>
        <jetty.version>9.4.7.v20170914</jetty.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <tomcat.version>8.0.28</tomcat.version>
    </properties>
</project>

我对KeyStoreLoader/ClientExampleRunner的修改。我修改了名称以匹配我的应用程序(即使在示例中),但最显着的变化是我动态解析机器名称

String hostName = InetAddress.getLocalHost().getHostName();
...
SelfSignedCertificateBuilder builder = new SelfSignedCertificateBuilder(keyPair)
    .setCommonName("...")
    .setOrganization("...")
    .setOrganizationalUnit("eng")
    .setLocalityName("...")
    .setStateName("...")
    .setCountryCode("...")
    .setApplicationUri("urn:" + hostName + ":OpcServer")
    .addDnsName("localhost")
    .addIpAddress("127.0.0.1");

在ClientExample中,我只改变了EndpointUrl。

您的实际项目的类路径中的某处似乎有旧版本的 Netty。

ByteBuf::writeMediumLE(以及所有其他 LE 后缀的 ByteBuf 方法)在 Netty 4.1 中引入。