Search code examples
javaintellij-ideaactivejdbc

Can't set up instrumentation for ActiveJDBC in Intellij IDEA Community


I'm trying to setup ActiveJDBC instrumentation in Intellij IDEA, but although I performed all of the steps from the instruction, I can't get it to work.

In my pom.xml I have the plugin enabled:

<build>
    <plugins>
        <plugin>
            <groupId>org.javalite</groupId>
            <artifactId>activejdbc-instrumentation</artifactId>
            <version>1.4.9</version>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>instrument</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Then I have created two tryout models that correspond with tables in my database: Client (to table clients) and SiteUrl (to table site_urls).

I have also enabled instrumentation as Maven goal after Make in default configuration for JUnit. Actually, it seems it runs fine:

**************************** START INSTRUMENTATION ****************************
Directory: /home/k-/Idea Projects/project/project/target/classes
**************************** END INSTRUMENTATION ****************************
**************************** START INSTRUMENTATION ****************************
Directory: /home/k-/Idea Projects/project/project/target/test-classes
Found model: package.persistance.Client
Found model: package.persistance.SiteUrl
Instrumented class: package.persistance.Client in directory: /home/k-/Idea%20Projects/project/project/target/classes/
Instrumented class: package.persistance.SiteUrl in directory: /home/k-/Idea%20Projects/project/project/target/test-classes/
**************************** END INSTRUMENTATION ****************************

But when I try to execute the following code, I get error:

public class FirstTests
{
    @Test
    public void saveTest() {
        Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/test_db", "root", "");
        Assert.assertTrue(Base.hasConnection());

        Client c = new Client();
        c.set("name", "client 1");
        c.saveIt();
    }
}

The error is:

org.javalite.activejdbc.DBException: failed to determine Model class name, are you sure models have been instrumented?

I can't figure out what might be wrong and how could I go about fixing it?

EDIT Tried building the project from command line. I'm not sure if I did it properly, here's the command I used:

mvn clean compile org.javalite:activejdbc-instrumentation:1.4.9:instrument assembly:single

But I still get the same error, asking if the models have been instrumented. But instrumentation output seems to be OK.


Solution

  • The problem is related to your directory having a space in a name:

    home/k-/Idea Projects/project/project/target/classes
    

    This issue: https://github.com/javalite/activejdbc/issues/91 has been fixed on February 7th 2014, but did not make it into the latest release. We will soon release version 1.4.10, but currently you can use a 1.4.10-SNAPSHOT from Sonatype repository that is free from this bug:

    Just add this to your pom and switch a version of ActiveJDBC and the Instrumentation plugin to snapshots:

    <repositories>
        <repository>
            <id>snapshots1</id>
            <name>Sonatype Snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>snapshots2</id>
            <name>Sonatype Snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>