I have 2 development PCs, both have following specification:
- Windows 10 1909 64 bit
- Installed Oracle JDK 1.8.0_281-b09
- Eclipse IDE for Java Developers 2020-12 (4.18.0)
The application under development is a Spring Boot project with following Maven file:
<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>com.my_company.example</groupId> <artifactId>test</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> <maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.source>${java.version}</maven.compiler.source> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-websocket --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports --> <dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>6.7.0</version> </dependency> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 --> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>2.0.7</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 --> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> <version>2.0.7</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4-rule-agent --> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4-rule-agent</artifactId> <version>2.0.7</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-javaagent --> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-javaagent</artifactId> <version>2.0.7</version> <scope>test</scope> </dependency> </dependencies> <modules> <module>core</module> <module>module1</module> <module>module2</module> </modules> </project>
When importing the project into Eclipse, one of development PC (called PC1) cannot build with following error:
On the other side PC (called PC2), the error does not happen, it can build and run successfully.
I checked both PCs, the Maven dependency still available:
To resolve the error, we added following dependency to POM.xml file:
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </dependency>
However, I want to ask why in PC1, it is needed to explicitly add the dependency, while in PC2 it is not necessary?
Later, I also build the JAR+WAR file from Eclipse (Run As > Maven Build... > select "package" in Goals field
).
Then deploy the JAR+WAR file to Docker container (base image is tomcat:9.0.11-jre8
).
The similar problem happen, the JAR file build from PC1 cannot run, while the JAR file build from PC2 still able to run. Error message:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
I also think that the problem come from PC1 as above. Could anyone help check if any possible cause for these problems?
Update
Based on answers from @M.Deinum
and @OneCricketeer
, I solved the problem.
In PC1, I installed JDK8, added to PATH.
The Eclipse IDE is downloaded from following link:
https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2021-03/R/eclipse-java-2021-03-R-win32-x86_64.zip
When check the Configuration, it still using the default Java 15 as follow:
So, the solution is to click Add...
as in the above image, then select the installed JDK (C:Program FilesJavajdk1.8.0_291
).
Update 2
This is feedback for @OneCricketeer
.
Uninstalled JDK from computer, but Eclipse still able to run the Java project.
Advertisement
Answer
Installed Oracle JDK 1.8.0_281-b09
Few things
One of the computer isn’t compiling the code with Java 8, otherwise jaxb would be available
Unless you’re maintaining old code, you should be using Java 11 at a minimum
If you absolutely need Java 8, it’s best to migrate to OpenJDK rather than Oracle’s distribution
And if it’s a brand new project, you can use any newer Java version, but worth pointing out that Spring Boot version should also be newer