0

My Persistence.xml is as follows:

<persistence-unit name="SARMPersistentUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>edu.deakin.sarms.model.StudentAccount</class>
    <class>edu.deakin.sarms.model.LecturerAccount</class>
    <class>edu.deakin.sarms.model.Unit</class>
    <class>edu.deakin.sarms.model.Enrollment</class>
    <class>edu.deakin.sarms.model.Attendance</class>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://xx.yy.ss:3306/t2"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="javax.persistence.jdbc.user" value="xx"/>
        <property name="javax.persistence.jdbc.password" value="ee"/>
        <property name="eclipselink.ddl-generation" value="drop-create-tables"/>

    </properties>
</persistence-unit>

pom.xml is as follows:

<?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>edu.deakin.sarms</groupId>
        <artifactId>sarms2</artifactId>
        <version>1.0-SNAPSHOT</version>

        <repositories>
            <repository>
                <id>oss.sonatype.org</id>
                <name>OSS Sonatype Staging</name>
                <url>https://oss.sonatype.org/content/groups/staging</url>
            </repository>
        </repositories>

        <dependencies>
             <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>eclipselink</artifactId>
                <version>2.5.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.eclipse.persistence</groupId>
                        <artifactId>commonj.sdo</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>javax.persistence</artifactId>
                <version>2.1.0</version>
            </dependency>

           <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>1.0.2</version>
            </dependency>



            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.6</version>
            </dependency>


        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                        <encoding>UTF-8</encoding>
                        <fork>true</fork>
                        <meminitial>128M</meminitial>
                        <maxmem>512M</maxmem>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>

                        <archive>
                            <manifest>
                                <mainClass>edu.deakin.sarms.service.SarmsControl</mainClass>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>

Still I am getting "java.lang.NoClassDefFoundError: javax/persistence/Persistence", on the line:

public static EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("SARMPersistentUnit");

Can anyone please suggest what am I doing wrong?

Cheers Ayesha

Andrzej Jozwik
  • 14,331
  • 3
  • 59
  • 68
theAntonym
  • 39
  • 1
  • 8
  • I created project and run from Idea - all works. How do you run your application? Try `mvn exec:java -Dexec.mainClass="edu.deakin.sarms.service.SarmsControl"` – Andrzej Jozwik Jun 02 '14 at 07:41
  • I am also working on idea. I did, mvn clean install. The tried java -jar . Your command was helpful, but I had another issue, the persistence.xml file was not under src/main/ instead of src/main/resources. So now my problem is fixed! – theAntonym Jun 03 '14 at 02:27

1 Answers1

0

I was doing a mvn clean install and then java -jar . Then I used the command mentioned by @ajozwk in the comment, but I had another issue, the persistence.xml file was under src/main/ instead of src/main/resources. So now my problem is fixed!

theAntonym
  • 39
  • 1
  • 8