Topics

Adding jdo-query to maven based project causes compile error


iansaucy@...
 
Edited

After my misguided attempt to get some help on github I'm trying to do it correctly here (:

 

I'm in the midst of setting up a JavaFX project with Datanucleu + JDO + JDOQL. I've got the first two parts working without issue, I've got a connection to the database, I can read and write no issues. When I go to add the JDOQL step, along with the maven plugin the compile fails with the following error.

`Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project projectName: Fatal error compiling: java.lang.NoClassDefFoundError: javax/jdo/annotations/PersistenceCapable: javax.jdo.annotations.PersistenceCapable -> [Help 1]`

I'm running OpenJDK 13, JavaFX 14 and the latest version of most datanucleus plugins/dependencies. I've got the persistence XML configured and that picks up alright, I'm setting properties inside that file as well.

I'm at a complete loss as to what the issue might be, I've compared my code to the examples and it seems basically identical. It seems like it can't find the dependencies for the JDO annotations, which doesn't make sense because it worked before adding this plugin. It does not even get to the point of generating the query classes, it fails before that step.
Any guidance would be great!

Here is my POM.XML

```
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.redacted</groupId>
    <artifactId>redacted</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <config.files.dir>${basedir}/src/main/resources</config.files.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <openjfx.Version>14</openjfx.Version>
        <openjfx.Maven.Version>0.0.4</openjfx.Maven.Version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>[5.1.6, 5.9)</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-rdbms</artifactId>
            <version>[5.1.6, 5.9)</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>javax.jdo</artifactId>
            <version>3.2.0-m13</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-jdo-query</artifactId>
            <version>[5.0.9, )</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>[1.2.17, )</version>
        </dependency>
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.30.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.Version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.Version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit5</artifactId>
            <version>4.0.16-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>datanucleus-maven-plugin</artifactId>
                <version>5.2.1</version>
                <configuration>
                    <persistenceUnitName>CentralUnit</persistenceUnitName>
                    <api>JDO</api>
<!--                    <props>${config.files.dir}/datanucleus.properties</props>-->
                    <log4jConfiguration>${config.files.dir}/log4j.properties</log4jConfiguration>
                    <verbose>true</verbose>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>com.redacted.App.Main</mainClass>
                    <systemProperties>
                        <systemProperty>
                            <key>log4j.configuration</key>
                            <value>file:${config.files.dir}/log4j.properties</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                    <compilerArgument>-AqueryMode=FIELD</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}</directory>
                            <includes>
                                <include>*.log</include>
                                <include>*.ods</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>${openjfx.Maven.Version}</version>
                <configuration>
                    <mainClass>es.deusto.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
        </plugins>
    </build>
</project>


```
My persistnce.XML


```
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1">

    <!-- JDO tutorial "unit" -->
    <persistence-unit name="CentralUnit">
        <class>es.deusto.User</class>
        <exclude-unlisted-classes/>
        <properties>
            <property name="javax.jdo.option.ConnectionURL" value="jdbc:sqlite:src/main/resources/database.db"/>
            <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
            <property name="datanucleus.schema.autoCreateAll" value="true"/>
            <property name="datanucleus.validateTables" value="true"/>
            <property name="datanucleus.validateConstraints" value="true"/>
            <property name="datanucleus.metadata.validate" value="false"/>
        </properties>
    </persistence-unit>
</persistence>
```

My User class
```import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import java.util.Date;


@PersistenceCapable
//@Inheritance(strategy= InheritanceStrategy.NEW_TABLE)
public class User {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
    protected long id;


    protected String firstName;
    protected String lastName;
    protected String notes;
    protected String phoneNumber;
    protected Date birthDate;
    protected Date dateJoined;
    protected Date createdAt;
    protected Date updatedAt;


    protected User(){};
//Omitted all the getters and setters```


Andy
 

If it fails before generating JDOQLTypedQuery classes (i.e the preCompile step), then where is it failing??

maven --debug
tells you way more than we see here. Posting the class is irrelevant if that class is never referenced in the error / exception.

Try an earlier JDK? I use v8, what DN is developed on. Cut the case down to something simpler with just a basic JDO class, and no RDBMS, java fx etc, since your problem is compile, not runtime.


iansaucy@...
 

It seems to be failing when it goes to search for the type annotation classes to compile resources using them? But my experiance with this type of thing is very little so I am extremely lost as pinning down the errors. My lack of detailed understanding on the Java compile process does not help either. I took the example for JDO type queries from github and adapted it to use JDK 8(It was configured for 1.6 I think). With Java 8 the example was happy to compile and run, so that definitely shows it's a java version issue.

Here is a gist of mvn --debug clean compile for my code on Java 13

https://gist.github.com/IanSaucy/76bd144139f14d50c61ec9dba4b328ce

In addition, here is one for mvn --debug clean compile for the example on Java 13, the error is slightly different but seems to be related to do the same thing.

https://gist.github.com/IanSaucy/a705758b51835ebbf54042026d262e62


So it sounds like I either need to downgrade to Java 8 (and JavaFX) or figure out what the actual issue is and try to fix it. If you/anyone has any pointers on what it might be I'm pretty keen to do some digging.

P.s. I noticed a lot of the examples on GitHub utilize outdated Java version(pre 1.8). Is there a standard for updating those? I'd love to help get them up to date so they're more relevant.

Thanks!


Andy
 
Edited

Compare the "maven --debug clean compile" output between JDK 8 and JDK 13 for a basic case. The real difference between those is "Jigsaw" (java modules) addition to the JDK. I don't use it.
Similarly compare the above output between the basic case with datanucleus-jdo-query (annotation processor present) and without datanucleus-jdo-query (no annotation processors present).


About updating ANY code in GitHub, you provide PULL REQUESTS to the relevant GitHub project, since this is open source. Thx


iansaucy@...
 

Thanks for giving me the direction to look in, I'll try see if I can remove the use of modules and maybe that will fix it.

 

I did just try something with Maven, I created a parent and child pom, the parent is the same minus the datanucleus-jdo-query dependency, the parent has a maven toolchain version of Java 13 while the child with only one dependency has a version of Java 8. This compiles, it actually does run without issues except for IntelliJ not being able to find the new compile classes(thus type enforcement does not work). This was more or less the way I went about doing this dual compile mode.

I have a feeling this is not a real solution....but I don't actually know. Here is a gist of those two poms though,
https://gist.github.com/IanSaucy/ce8d29c4c27462714d66dab285f71141

Thanks again!