Problems with Maven when changing code?

I am trying to run a little Maven test program using NetBeans. Now the NetBeans-given code works perfectly fine with Maven. Compiling, running, all good. But when I change anything, like adding an FXML-File or adding JPA persistence, I then get errors when starting the program. Compiling seems to work, but I can't start the program. I expect the error to be somewhere in the configuration of Maven, but I can't find it. The code by itself should work just fine.

Ok, to show you guys what exactly I mean, here is the code. I just add a JPA-persistence to a MySQL-Database. After adding the program doesn't run anymore.

package com.myproject.mavenproject;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

 * Hello world!
public class App 
    public static void main( String[] args )
        System.out.println( "Hello new World!" );

        EntityManagerFactory emf = Persistence.createEntityManagerFactory( "GlassesPU" );
        try {
            EntityManager     em = emf.createEntityManager();
            EntityTransaction tx = null;
            try {
                tx = em.getTransaction();

                Hund hund = new Hund();

                //em.persist( entity1 );
                //em.merge( entity2 );
                //em.find( MyEntity.class, id );
            } catch( RuntimeException ex ) {
                if( tx != null && tx.isActive() ) tx.rollback();
                throw ex;
            } finally {
        } finally {

package com.myproject.mavenproject;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

public class Hund implements Serializable {
    private static final long serialVersionUID = 1L;
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String formerName;
    private String newName;

    public Long getId() {
        return id;

    public void setId(Long id) { = id;

    public String getFormerName() {
        return formerName;

    public void setFormerName(String formerName) {
        this.formerName = formerName;

    public String getNewName() {
        return newName;

    public void setNewName(String newName) {
        this.newName = newName;

    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;

    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Hund)) {
            return false;
        Hund other = (Hund) object;
        if (( == null && != null) || ( != null && ! {
            return false;
        return true;

    public String toString() {
        return "com.myproject.mavenproject.Hund[ id=" + id + " ]";



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <persistence-unit name="com.myproject_MavenProject_jar_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/glasses?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.password" value="mypassword"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>


<project xmlns="" xmlns:xsi=""





Error message:

cd /home/myuser/NetBeansProjects/MavenProject; JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51 /home/myuser/netbeans-7.4/java/maven/bin/mvn "-Dexec.args=-classpath %classpath com.myproject.mavenproject.App" -Dexec.executable=/usr/lib/jvm/jdk1.7.0_51/bin/java org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...

Building MavenProject 1.0-SNAPSHOT

--- exec-maven-plugin:1.2.1:exec (default-cli) @ MavenProject ---
Hello new World!
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named GlassesPU
    at javax.persistence.Persistence.createEntityManagerFactory(
    at javax.persistence.Persistence.createEntityManagerFactory(
    at com.myproject.mavenproject.App.main(
Total time: 0.891s
Finished at: Mon Feb 03 21:35:25 CET 2014
Final Memory: 5M/111M
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project MavenProject: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1]

Anyone has an idea what the problem could be?


There is no problem with Maven. It's only reporting the error. It says that it can't find a persistence provider called "GlassesPU".

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named GlassesPU

Your persistence.xml has another name:

<persistence-unit name="com.myproject_MavenProject_jar_1.0-SNAPSHOTPU" ... >

Try changing it to "GlassesPU":

<persistence-unit name="GlassesPU" ...>

If Maven complains again, it will probably be due to something else.

Need Your Help

Exporting output of a command to a variable only if succesful (Bash set -e)

linux bash shell error-handling command

I would like the following script to fail. (and still print err to stderr)