重大错误:无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.0:compile(默认编译):编译失败

时间:2019-03-16 05:36:38

标签: java maven

我正在尝试使用Java开放源代码框架和必要的配置来构建REST API,这将能够构建和测试第一个Web服务。 克隆项目并下载所有必需的依赖项后,我尝试通过使用以下命令使用maven构建war文件:
mvn clean package
但是之后,生成了以下编译错误

C:\Users\lenovo\Desktop\REST>mvn clean package
[INFO] Scanning for projects...
[INFO] Building REST services 1.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ rest ---
[INFO] Deleting C:\Users\lenovo\Desktop\REST\target
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ rest ---
[INFO] Compiling 10 source files to C:\Users\lenovo\Desktop\REST\target\classes
[ERROR] COMPILATION ERROR :
[ERROR] /C:/Users/lenovo/Desktop/REST/src/main/java/com/ami/entity/Product.java:[5,33] package javax.xml.bind.annotation does not exist
[ERROR] /C:/Users/lenovo/Desktop/REST/src/main/java/com/ami/entity/Product.java:[40,6] cannot find symbol
symbol:   class XmlAttribute
 location: class com.ami.entity.Product
[ERROR] /C:/Users/lenovo/Desktop/REST/src/main/java/com/ami/entity/Product.java:[50,6] cannot find symbol
symbol:   class XmlAttribute
location: class com.ami.entity.Product

上述位置是:

package com.ami.entity;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlAttribute;


@Entity
@Table(name = "product")
public class Product implements java.io.Serializable {
private static final long serialVersionUID = -2107661175822965352L;
 private String itemId;
 private String itemName;
private String itemDesc;
private String createdBy;
private String updatedBy;
private Date createdAt;
private Date updatedAt;
public Product() {
}


@Id
@Column(name = "id", unique = true, nullable = false)
public String getItemId() {
    return this.itemId;
}
public void setItemId(String catGuid) {
    this.itemId = catGuid;
}

@Column(name = "name", unique = true, nullable = false)
@XmlAttribute(name="name")
public String getItemName() {
    return this.itemName;
}

public void setItemName(String catName) {
    this.itemName = catName;
}

@Column(name = "description", nullable = false)
@XmlAttribute(name="description")
public String getItemDesc() {
    return this.itemDesc;
}

public void setItemDesc(String catDesc) {
    this.itemDesc = catDesc;
}

@Column(name = "created_by")
public String getCreatedBy() {
    return this.createdBy;
}

public void setCreatedBy(String createdBy) {
    this.createdBy = createdBy;
}

@Column(name = "updated_by")
public String getUpdatedBy() {
    return this.updatedBy;
}

public void setUpdatedBy(String updatedBy) {
    this.updatedBy = updatedBy;
}

@Column(name = "created_at")
public Date getCreatedAt() {
    return this.createdAt;
}

public void setCreatedAt(Date createdAt) {
    this.createdAt = createdAt;
}

@Column(name = "updated_at")
public Date getUpdatedAt() {
    return this.updatedAt;
}

public void setUpdatedAt(Date updatedAt) {
    this.updatedAt = updatedAt;
}


}

有人可以帮忙吗!

2 个答案:

答案 0 :(得分:0)

对于您作为Java 8用户,请扫描您的类路径以查找可能冲突的jaxb库。

例如,执行mvn dependency:tree并验证是否不存在可能与JRE中存在的JAXB实现冲突的其他JAXB实现。

答案 1 :(得分:0)

在pom.xml中添加Java 11 XML实用程序类解决了我的问题。 以下代码部分已添加到现有pom.xml中:

<dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.0</version>
        </dependency>

克隆项目并重新下载所有必需的依赖项之后。.使用maven通过使用命令mvn clean package生成war文件。