0

I'm trying to use ActiveJDBC's dynamic instrumentation with the -javaagent command-line option in the run configuration of a JUnit test in Intellij IDEA (2018.1 Ultimate). I've entered the following in the "VM Options" input field of the run configuration dialog:

-javaagent:"C:\Users\cschabli\.m2\repository\org\javalite\activejdbc-instrumentation\2.0\activejdbc-instrumentation-2.0.jar" -Dactivejdbc-instrumentation.log=true

After starting the unit test, I get log messages of the ActiveJDBC instrumentation agent like these:

ActiveJDBC Instrumentation - You are using dynamic instrumentation
ActiveJDBC Instrumentation - Found model: foo.bar.MyModel

But when the application code accesses the model class, I get this error message:

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

Why doesn't this work in IDEA?

3 Answers3

0

I used you configuration on a project ActiveWeb - Simple:

pretty much using your configuration. All worked as expected, see the screenshot.

However, Dynamic Instrumentation has its limitations with Java8 Lambdas.

If instrumentation is annoying and gets in a way, you can configure a simple script like this as an "External Tool" in Intellij Idea:

#!/usr/bin/env bash

## This script will instrument fast without Maven
## Adjust versions on the classpath if upgrading!
export JAVALITE=2.0

export CLASSPATH=~/.m2/repository/org/javalite/activejdbc-instrumentation/$JAVALITE/activejdbc-instrumentation-$JAVALITE.jar
export CLASSPATH=${CLASSPATH}:~/.m2/repository/org/javassist/javassist/3.18.2-GA/javassist-3.18.2-GA.jar
export CLASSPATH=${CLASSPATH}:~/.m2/repository/org/javalite/activejdbc/$JAVALITE/activejdbc-$JAVALITE.jar
export CLASSPATH=${CLASSPATH}:target/classes

java   -classpath $CLASSPATH  -DoutputDirectory=target/classes 
org.javalite.instrumentation.Main

This is what I'm using personally. This script avoids Maven startup delay, and executes in less than a second on a project with more than 100 tables!

I configured it to start by default before any JUnit test.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • Did you execute `mvn:clean` before running the `BookSpec` test in IDEA? I tried to reproduce your example, but get the "Have you instrumented your models" error with a clean workspace, although the instrumentation agent emits its messages. Only after executing the activejdbc-instrumentation Maven goal, the example works for me. – Christof Schablinski Jul 18 '18 at 09:49
  • you are correct, the instrumentation broke after I cleaned the project. Not sure why, will need a serious dive into some non-trivial code. Have you tried the script I suggested? – ipolevoy Jul 18 '18 at 21:39
  • The script solution works. I assume the problem with the IDEA solution is rather an IDEA issue. I asked Jetbrains for support. – Christof Schablinski Jul 19 '18 at 06:55
  • In ll honesty, the dynamic instrumentation is not being used much. I suggest to use static instrumentation in general. I think dynamic instrumentation will be pulled from framework because it conflicts with Java Lambda instrumentation. – ipolevoy Jul 19 '18 at 12:43
0

Feedback from Jetbrains:

For Gradle projects you can tell IDEA to delegate IDE build/run actions to Gradle (see option Preferences | Build, Execution, Deployment | Build Tools | Gradle | Runner | Delegate IDE build/run actions to gradle).

For Maven projects there is currently no solution. They have filed the issue IDEA-195924.

0

I found a way around this problem for Gradle, IntelliJ.

Instead of running from the green arrow on the top, go to Gradle (in the right of screen) --> Tasks --> Application --> run

This one should work, as instrumentation happens properly with this run.

hiteshn97
  • 97
  • 3
  • 10