Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Project's JDK aren't being used during build(JDK set in project's build path aren't being used during build, causing java.lang.NoClassDefFoundError: javax/xml/bind/JAXBElement)
Project's JDK aren't being used during build [message #1832430] Thu, 17 September 2020 17:39 Go to next message
Lincoln Alves is currently offline Lincoln AlvesFriend
Messages: 2
Registered: August 2020
Junior Member
Greetings!

I'm currently using Eclipse 2020-09 (which comes with it's own JRE). My workspace has a few Java 8 projects and a Java 7 one.

The problem: when Eclipse builds these projects, a few internal errors appear on Mapper interfaces (annotated with Mapstruct @Mapper):

Internal error in the mapping processor: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBElement 
at org.mapstruct.ap.internal.model.source.builtin.JaxbElemToValue.<init>(JaxbElemToValue.java:41)
at org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods.<init>(BuiltInMappingMethods.java:49)
at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl.<init>(MappingResolverImpl.java:99)
at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:98)
at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:76)
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:270)  	
at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:250)
at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:216)
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:155)  	
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:142)
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:124)
at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:171)  	
at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)  	
at org.eclipse.jdt.internal.compiler.Compiler.processAnnotationsInternal(Compiler.java:958)
at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:932)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:450)  	
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)  	
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:386) 
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:214)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:318)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:275)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:187)  	
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:832)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) 
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)  	
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)  	
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:154)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:244)  	
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBElement  	
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)  	
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)  	... 35 more  


In my researches, I've found this is the expected behaviour when using Java 11+, as the package javax.xml.bind was removed since this version. This leads me to believe Eclipse is not using the JDK I've set on my projects while building (or maybe when analysing @Mapper annotations?). Is this the expected behaviour? Am I missing something?

Thank you!

[Updated on: Thu, 17 September 2020 17:45]

Report message to a moderator

Re: Project's JDK aren't being used during build [message #1832444 is a reply to message #1832430] Fri, 18 September 2020 07:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31702
Registered: July 2009
Senior Member
Only some of the packages (C/C++, JavaScript, and Rust) come with their own JRE, not all of them. And the installer (which comes with it's own JRE) creates installations that use the JRE/JDK that you choose. In all cases, for 2020-09 this must be a Java 11 JDK/JRE. And yes, JEE libraries such as JAXB are no longer part of the JDK.

But note that your projects use the JRE configured in Window -> Preferences -> Java -> Installed JREs. This, when first initialized, will include the JRE/JDK used by the running installation. This will of course be Java 11 or higher for 2020-09. But you can add JREs here and specify any JRE/JDK including a Java 8 one.

That all being said, your stack trace shows that org.mapstruct.ap.MappingProcessor is used in the running IDE itself so it doesn't matter what JRE you specify for the workspace. The org.mapstruct.ap.MappingProcessor bundle has no doubt not be tested to work with Java 11 but rather assumes that its running with Java 8 and that javax.xml.bind.JAXBElement is available in the JDK/JRE of the running installation. This is now a bad assumption.

The analogous problem was raised in this thread:

https://www.eclipse.org/forums/index.php/mv/msg/1105222/1832329/#msg_1832329

That thread also outlines what is needed to fix that problem. I.e., a package import is needed in the bundle that uses JAXB and the JEE/Jakarta bundles that implement these packages also need to be installed...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Project's JDK aren't being used during build [message #1832576 is a reply to message #1832444] Mon, 21 September 2020 09:49 Go to previous messageGo to next message
David Garratt is currently offline David GarrattFriend
Messages: 31
Registered: July 2011
Member
I need to understand what is being said here before I upgrade from 2020 06 to 2020 09. I am running on MacOS and all my projects are using Java 8. In addition Java 8 is the default for command line ANT scripts / Tomcat Servers etc.
I have specified the JDK that I want to use for each of my Eclipse Projects. I don't want to change the default enviroment for my whole machine.

If I upgrade to 2020 09 and it installs a newer JDK what impact is this going to have outside of the Eclipse IDE ?

Many thanks

Dave
Re: Project's JDK aren't being used during build [message #1832668 is a reply to message #1832576] Wed, 23 September 2020 07:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31702
Registered: July 2009
Senior Member
Given your stack trace, it appears you're already using Java 11 to run the IDE and all packages for Eclipse 2020-09 do require Java 11 to run. There's nothing you can personally do to make org.mapstruct.ap work on Java 11. The folks who provide that need to provide a new version that works on Java 11. So if you need org.mapstruct.ap, you'll have to stick to an Eclipse version that doesn't require Java 11, i.e., 2020-06.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:I can't open java codes
Next Topic:Modifying project_loc inside a program
Goto Forum:
  


Current Time: Mon Jan 18 03:37:00 GMT 2021

Powered by FUDForum. Page generated in 0.03559 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top