1

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.

moskalak
  • 271
  • 2
  • 12
  • So the instrumentation works on the command line, or through your build script (Maven, Ant, Gradle, etc), right? – Makoto Nov 08 '14 at 23:38
  • I guess it works through the build script. This is what I get in the "Output" window in IDEA, right after that it goes to running the actual code and then that's where the error comes from. I'll update the question with pictures. – moskalak Nov 08 '14 at 23:39
  • So instead of running the Maven goal from within IntelliJ, try running it on the command line and see if that works. If it does, then we can isolate it to being an IntelliJ-specific issue. – Makoto Nov 08 '14 at 23:46
  • I tried building with Maven from terminal, but still got the error. I added the exact command I used to the question. – moskalak Nov 09 '14 at 00:49

1 Answers1

2

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>
ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • I can't thank you enough. At the same time, I feel stupid. I saw that `~/Idea%20Projects` directory, but it didn't bother me at all. – moskalak Nov 09 '14 at 01:51
  • do not feel stupid, this was a bug in the framework:) – ipolevoy Nov 09 '14 at 02:01
  • Yeah, but that could've set me off about what could be wrong. Still, I simply moved all my projects to `~/idea-projects` -- just to keep being on the safe side. :) – moskalak Nov 09 '14 at 02:09