Я пытаюсь создать пример проекта maven, но он выдает ошибку ниже.Я добавил все необходимые банки на проект.Не уверен, в чем проблема.
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project MySampleProj: Compilation failure: Compilation failure:
Любая помощь будет оценена.
<?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>MySampleProj</groupId>
<artifactId>MySampleProj</artifactId>
<version>0.0.2-SNAPSHOT</version>
<name>MySampleProj</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven-compiler-plugin-version>3.7.0</maven-compiler-plugin-version>
<cxf.version>3.1.6</cxf.version>
<jra.version>2.1.16</jra.version>
<jdk.version>1.7</jdk.version>
<jaxws.version>2.0.1</jaxws.version>
<spring.version>5.0.6.RELEASE</spring.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<compilerVersion>${java.version}</compilerVersion>
<executable>${java.home}/bin/javac</executable>
</configuration>
</plugin>
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version> <configuration> <release>8</release> <verbose>true</verbose>
</configuration> </plugin> -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Class
import java.net.URLEncoder;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
public class DemoRestClient {
public static void main(String[] args) {
DemoRestClient restClient = new DemoRestClient();
try {
restClient.getBook("Naked Sun");
} catch (Exception e) {
e.printStackTrace();
}
}
public BookVO getBook(String bookName) throws Exception {
String output = null;
try{
String url = "http://localhost:8080/weblog4jdemo/bookservice/getbook/";
url = url + URLEncoder.encode(bookName, "UTF-8");
HttpClient client = new HttpClient();
PostMethod mPost = new PostMethod(url);
client.executeMethod( mPost );
Header mtHeader = new Header();
mtHeader.setName("content-type");
mtHeader.setValue("application/x-www-form-urlencoded");
mtHeader.setName("accept");
mtHeader.setValue("application/xml");
mPost.addRequestHeader(mtHeader);
client.executeMethod(mPost);
output = mPost.getResponseBodyAsString( );
mPost.releaseConnection( );
System.out.println("out : " + output);
}catch(Exception e){
throw new Exception("Exception in retriving group page info : " + e);
}
return null;
}
public void addBook(String bookName, String author) throws Exception {
String output = null;
try{
String url = "http://localhost:8080/weblog4jdemo/bookservice/addbook";
HttpClient client = new HttpClient();
PostMethod mPost = new PostMethod(url);
mPost.addParameter("name", "Naked Sun");
mPost.addParameter("author", "Issac Asimov");
Header mtHeader = new Header();
mtHeader.setName("content-type");
mtHeader.setValue("application/x-www-form-urlencoded");
mtHeader.setName("accept");
mtHeader.setValue("application/xml");
mPost.addRequestHeader(mtHeader);
client.executeMethod(mPost);
output = mPost.getResponseBodyAsString( );
mPost.releaseConnection( );
System.out.println("output : " + output);
}catch(Exception e){
throw new Exception("Exception in adding bucket : " + e);
}
}
}
Console output
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project MySampleProj: Compilation failure: Compilation failure:
[ERROR] /C:/User....DemoRestClient.java:[5,37] package org.apache.commons.httpclient does not exist
[ERROR] /C:/User....DemoRestClient.java:[7,37] package org.apache.commons.httpclient does not exist
[ERROR] /C:/User....DemoRestClient.java::[8,45] package org.apache.commons.httpclient.methods does not exist
[ERROR] /C:/User....DemoRestClient.java:[7,24] package javax.ws.rs.core does not exist
[ERROR] /C:/User....DemoRestClient.java:[12,1] package javax.ws.rs does not exist