1
resposta

Erro ao rodar o programa

Segue erro abaixo, ao clicar em Run As Java Application:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlRootElement
    at org.apache.camel.model.OptionalIdentifiedDefinition.getShortName(OptionalIdentifiedDefinition.java:79)
    at org.apache.camel.impl.DefaultNodeIdFactory.createId(DefaultNodeIdFactory.java:36)
    at org.apache.camel.model.RouteDefinitionHelper.forceAssignIds(RouteDefinitionHelper.java:152)
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:930)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3245)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2968)
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:172)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2799)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2795)
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2818)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2795)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2764)
    at br.com.caelum.camel.RotaPedidos.main(RotaPedidos.java:21)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlRootElement
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 14 more
package br.com.caelum.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class RotaPedidos {

    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("file:pedidos?delay=5s").
                to("file:saida");

            }
        });
        context.start();
        Thread.sleep(20000);
        context.stop();
    }

}
1 resposta
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlRootElement

Esse erro é por conta da versão do JDK ser Java 9 ou superior (no Java 8 funciona).

Adiciona o codigo abaixo no pom.xml do seu projeto:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>