Bhavya
Bhavya

Reputation: 16172

MAVEN BUILD FAILURE: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) : Compilation failure

I am trying to build REST API's,using the java open source frameworks and necessary configs.That would be able to build and test first webservice. After cloning the project and downloading all the required dependency I attempted to build a war file using maven by using below command
mvn clean package
But after this the following compilation errors were generated

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

The above mentioned location is:

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;
}


}

Can someone please help!

Upvotes: 2

Views: 6526

Answers (2)

Bhavya
Bhavya

Reputation: 16172

Adding Java 11 XML utility classes in pom.xml solved my problem. The following part of code is added in the existing 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>

After cloning the project and downloading all the required dependency again.. war file is generated using maven by using command mvn clean package.

Upvotes: 4

mle
mle

Reputation: 2542

For you as a Java 8 user, please scan your classpath for potentially conflicting jaxb libraries.

For example do a mvn dependency:tree and verify, that no other JAXB implementations are present that could conflict with those which reside in your JRE.

Upvotes: 2

Related Questions