how to add dom4j dependecy in maven pom with spring boot - java

I want to use dom4j to parse xml string. But when I add dom4j dependency in pom file, my dev tool(Eeclipse) prompt errors below:
I tried to refresh project and maven's update project, the errors still occured. If remove the dependency, all of errors disappear, also dom4j cannot use.
Eclipse version:
Eclipse Java EE IDE for Web Developers.
Version: Photon Release (4.8.0)
Build id: 20180619-1200
POM file:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Maven Version:

I figured out it through a whole day working, the fix steps are:
1. the first line of errors prompt in eclipse is : fail to read artifact descriptor for xml-apis:xml-apis:jar:1.4.01.(the first capture image of the question)
2. I assumed that something are wrong with xml-apis in maven repository, so I find the directory of xml-apis in maven repository and remove them all
3. After that, I use Maven->Update project in eclipse, the errors run away.
I think the reason is: some files of xml-apis were damaged.

Related

ComponentLookupException when importing java project into intellij Idea

I just download a spring boot project from https://start.spring.io/ and imported it into intellij idea, then I choose import module selecting the pom.xml file but when I click on Apply I get the error:
java.lang.RuntimeException: java.lang.RuntimeException: org.codehaus.plexus.component.repository.exception.ComponentLookupException: com.google.inject.ProvisionException: Unable to provision, see the following errors:
Here's the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.springframework.amqp.tutorials</groupId>
<artifactId>rabbitmq-amqp-tutorials</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rabbitmq-amqp-tutorials</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
EDIT:SOLUTION
As pointed out by #Sanura Hettiarachchi there is a bug with the edition of intellij idea I was using, uninstalling and installing the latest version (Intellij Idea 2022.2.3 Community Edition) solved the problem. Now importing an existing project works nicely, no need to manually import modules.
It's not clear what you are trying to achieve. You click "open or import" and add the existing project. After that you try to import the same project again.
If you want to load the maven dependancies right click on the "pom.xml" and select "maven->reload project"
Update:
The issue seems to be on intelliJ IDE older versions which should be fixed by now.
https://youtrack.jetbrains.com/issue/IDEA-290419/Maven-385-NoSuchMethodError-orgapachemavenmodelvalidationDefaultModelValidator-method-void-init-not-found

Unable to use java.net.http in Maven project using Spring Java 12

I am trying to use java.net.http library to use HTTP functions, however my IntelliJ compiler is not recognizing it.
The error I receive on the package side: java: error: "invalid target release: 12"
in regards to the entire project here is another error that I receive: Plugin 'org.springframework.boot:spring-boot-maven-plugin:' not found
I have made sure I properly installed Java 12 as well as set it as the project & target bytecode version. Im relatively new to coding in this environment so if there's anything I can do to better describe my question please let me know.
Here is the maven pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.rooseveltthedev</groupId>
<artifactId>coronavirus-tracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>coronavirus-tracker</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>12</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is the code where I am having difficulty with the HTTP import:
import java.net.http.HttpClient;
public class CoronaVirusDataService {
public static String VIRUS_DATA_URL = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv";
public void fetchVirusData(){
HttpClient client = HttpClient.newHttpClient();
}
}
also I noticed there are some lines that refuse to go into the code formatting any remarks on how to fix that for future questions would be great.
This should be some maven project / compiler and/or class-path related issue in your development environment.
I could not reproduce your error.
I am successfully using java.net.http.HttpClient with Spring Boot 2.4 and Java 12 (also Java 11 LTS!). HttpClient is connecting getting back 200 status codes...
Any issues you have is not related to java.net.http libraries with Spring Boot and Java 12...
I would try to mvn compile and package using command line without the IDE. Also, do you need spring boot dev-tools runtime dependency in your pom? Try to remove it...

Exception in thread "Thread-2" java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;) for PACT tests

I'm getting this kotlin exception when trying to run some PACT tests using Java and not sure how to fix it please.
Here the error :
Exception in thread "Thread-2" java.lang.NoSuchMethodError:
kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)[B
EDIT
I've updated my PACT dependencies to use more up to date versions, and I'm still getting the same issue, however only when I have the below dependency as part of it and not sure why.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
This is my current pom:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hmhco</groupId>
<artifactId>update-catalog</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<properties>
<rest-assured.version>3.0.0</rest-assured.version>
<json-schema-validator.version>3.3.0</json-schema-validator.version>
</properties>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${json-schema-validator.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-junit5</artifactId>
<version>4.0.10</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit</artifactId>
<version>4.0.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven</artifactId>
<version>4.0.10</version>
<configuration>
<pactDirectory>target/pacts</pactDirectory>
<pactBrokerUrl>http://pact-broker-hmh.devel.hmheng-qe.brnp.internal/</pactBrokerUrl>
<projectVersion>${project.version}</projectVersion>
<trimSnapshot>true</trimSnapshot>
</configuration>
</plugin>
</plugins>
</build>
And that's what I see when look for Kotlin after running maven dependency tree. The complete project can be found here.
Thanks very much.
A possible reason you are getting that error (I'm assuming) is because you are mixing major versions of the Pact libraries.
<pact.version>3.5.24</pact.version>
<pact-jvm-provider-maven.version>3.5.9</pact-jvm-provider-maven.version>
<pact-jvm-maven.version>3.5.24</pact-jvm-maven.version>
<pact.jvm.consumer.junit.version>4.0.10</pact.jvm.consumer.junit.version>
You have versions 3.5.9, 3.5.24 and 4.0.10. You should use the same major version.
Versions 3.5.x are mostly written in Kotlin (probably version 1.2.x), while version 4.0.x is written using Kotlin 1.3.x.
I'm not sure why Sprinboot is impacting things, but maybe a Spring dependency is also bringing in a version of the Kotlin standard library.
The best thing to do is use version 4.0.10 for all the Pact libraries, then run the Maven dependency tree plugin and check that versions of the Kotlin standard libraries that are being used.

Why is GWT 2.5.1 missing from Maven repo?

I just installed m2e (the Maven Eclipse plugin) and created a new Maven Project with a Quickstart archetype. I then went to the official Maven repo to pull down GWT 2.5.1's dependencies, and see that it wants you to add the following <dependency> element to your project's pom.xml file:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>2.5.1</version>
</dependency>
So, altogether, my pom.xml looks like:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me.myorg</groupId>
<artifactId>maven-resolver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>maven-resolver</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
</project>
I am getting the following error:
Missing artifact com.google.gwt:gwt:jar:2.5.1
And furthermore, in Eclipse's Package Explorer, under my project's Maven Dependencies library, nothing is resolving.
What's going on here? Thanks in advance!
Update: the contents of ~/.m2/repository/com/google/gwt/gwt/2.5.1 are as follows:
gwt-2.5.1.jar.lastUpdated gwt-2.5.1.pom.sha1
gwt-2.5.1.pom _maven.repositories
This gwt dependencie it's a parent pom for the gwt project. This means that the repo will only contain the hash and the pom, but not the jar.
You need to use two libraries: gwt-servlet and gwt-user:
I've found this configuration for GWT development (maybe you don't need to put the <scope> as described):
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>2.5.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<dependencies>
Remove your dependencies and update your pom with these two shown above.
You can also use the gwt-maven-plugin to manage your gwt project and deploy via maven. I've found this information there.
I hope that works!

how to add project jar into eclipseworkspace\.metadata\.plugins\serverfolder\projectfolder\web-inf\lib

i am using Eclipse IDE. i have a maven projects as lmexadapter-core-api, lmexadapter-core-impl, lmex-moodle-api, lmexserver-mobile-api, lmexadapter-moodle-api, lmexadapter-moodle-impl. i have dependency in pom as below :
<parent>
<artifactId>lmexadapter-moodle</artifactId>
<groupId>com.platysgroup.lmex.adapter</groupId>
<version>1.0</version>
</parent>
<groupId>com.platysgroup.lmex.adapter</groupId>
<artifactId>lmexadapter-moodle-web</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>Maven Webapp Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.platysgroup.lmex.adapter.core</groupId>
<artifactId>lmexadapter-core-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.platysgroup.lmex.adapter.core</groupId>
<artifactId>lmexadapter-core-impl</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.platysgroup.lmex.server.mobile</groupId>
<artifactId>lmexserver-mobile-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.platysgroup.lmex.adapter.moodle</groupId>
<artifactId>lmexadapter-moodle-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.platysgroup.lmex.adapter.moodle</groupId>
<artifactId>lmexadapter-moodle-impl</artifactId>
<version>${project.version}</version>
</dependency>
i am using tomcat as my application server. i get all the jar except lmexadapter-moodle-api, lmexadapter-moodle-impl in my D:\EclipseWorskpace\ew-pg\lmexadapter.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\lmexadapter-moodle-web\WEB-INF\lib. because of this application is unable to locate class of lmexadapter-moodle-impl. what should i have to define so it will take both jar in a specified path as above.
please help me.
Thank you
Assuming current version of Eclipse and Maven plugin, is this something that can be solved by adding Maven dependencies to "project deployment assembly"?
If you have your project configured as Dynamic Web Project and Tomcat as server in Eclipse, this is under Project->Deployment Assembly->Add->java build path entries -> Maven dependencies.

Categories

Resources