简体   繁体   中英

Generate JAX-WS classes using wsgen plugin

I am trying to generate the wsdl and the classes to publish the service but when I try to publish and run the generated classes these ones missmatch the current java compiler version.

I am using eclipse Eclipse version 2021-12

jdk1.8.0_321

If I check the java version in windows 10 is 8 but when I check it from the terminal in eclipse is 17.

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/motorservice/ws/jaxws/GetLibroById has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at com.sun.xml.ws.model.RuntimeModeler.getRequestWrapperClass(RuntimeModeler.java:341)
    at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:771)
    at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:701)
    at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:461)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:290)
    at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:70)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:44)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:28)
    at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:90)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:491)
    at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:270)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:134)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:548)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:530)
    at com.sun.xml.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:304)
    at com.sun.xml.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:217)
    at com.sun.xml.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:111)
    at javax.xml.ws.Endpoint.publish(Endpoint.java:240)
    at com.motorservice.ws.Publicador.main(Publicador.java:8)

the pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.motorservice.ws</groupId>
    <artifactId>motorservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>motorservice</name>

    <dependencies>

        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.3.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>

                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>

            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsgen</goal>
                        </goals>

                    </execution>

                </executions>
                <configuration>
                    <sei>com.motorservice.ws.GestorLibrosImpl</sei>
                    <genWsdl>true</genWsdl>
                    <keep>true</keep>
                    <sourceDestDir>src/main/java</sourceDestDir>

                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Interface

/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.3.2
 * Generated source version: 2.2
 * 
 */
@WebService
public interface GestorLibros {


    @WebMethod
    public List<Libro> listarLibros();
    
    @WebMethod
    public Libro getLibroById(String numSerie) throws NotFoundException;

}

Impl.

package com.motorservice.ws;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;


@WebService(endpointInterface = "com.motorservice.ws.GestorLibros")
public class GestorLibrosImpl implements GestorLibros {

    public List<Libro> listarLibros() {
        List<Libro> listaLibros = new ArrayList<Libro>();
        listaLibros.add(new Libro("planeta", "la sombra del viento", "isb123"));
        listaLibros.add(new Libro("planeta", "puertas de piedra", "isbn231"));
        return listaLibros;
    }

    public Libro getLibroById(String numSerie) throws NotFoundException {
        List<Libro> listaLibros = listarLibros();
        int i = 0;
        while (i < listaLibros.size() && !numSerie.equals(listaLibros.get(i).getSerie())) {
            i++;
        }
        
        if(i == listaLibros.size()) {
            throw new NotFoundException();
        }
        return listaLibros.get(i);
    }

}

Project structure.

Project Estructure image link

SOLVED:

I have updated from maven version 3.8.1 to 3.8.4 and try "mvn clean compile -X" and it works. I think "mvn clean compile" solved it

SOLVED:

I have updated from maven version 3.8.1 to 3.8.4 and try "mvn clean compile -X" and it works. I think "mvn clean compile" solved it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM