代码之家  ›  专栏  ›  技术社区  ›  Bhavya

MAVEN生成失败:未能执行目标org.apache.maven网站.插件:maven编译器插件:3.0:compile(默认编译):编译失败

  •  1
  • Bhavya  · 技术社区  · 7 年前

    我正在尝试构建REST API,使用java开源框架和必要的配置将能够构建和测试第一个webservice。 在克隆项目并下载所有必需的依赖项之后,我尝试使用下面的命令使用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;
    }
    
    
    }
    

    有人能帮忙吗!

    0 回复  |  直到 7 年前
        1
  •  1
  •   mle    7 年前

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

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

        2
  •  1
  •   Bhavya    7 年前

    在中添加Java11XML实用程序类pom.xml文件解决了我的问题。 在现有的pom.xml文件:

    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
    </dependency>
    <依赖关系>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <版本>2.3.0</版本>
    </依赖关系>
    <依赖关系>
    <组ID>com.sun.xml网站。绑定</groupId>
    <artifactId>jaxb-impl</artifactId>
    <版本>2.3.0</版本>
    </依赖关系>

    在克隆项目并再次下载所有必需的依赖项之后。。war文件是使用maven命令生成的 mvn clean package .