Problem with instrumentation

78 views
Skip to first unread message

Hugo Alexandre Aguera Viana

unread,
Apr 19, 2015, 6:44:35 PM4/19/15
to activejd...@googlegroups.com
Hi,
I have a problem as the instrumentation code below
Would you like a help please
Thanks

ServerFX.java
                     else if (send.op.toUpperCase().contains("SELECT")) {
                        obj = ae.list(send.obj.getTable(),send.obj.getWhere(),send.obj.getOffset(),send.obj.getLimit(),send.obj.getOrderBy(),send.obj.getParams());


ActiveEntity.java
    public List list(String table, String where, int offset, int limit, String orderBy, Object... params) {
        Object m = null;
        m = getTable(table);
        Model model = null;
        
        if (m instanceof Banco) {
            model = (Banco) m;
        }
        System.out.println("Model.: "+model.getMetaModel().toString());
    }

    protected Object getTable(String table) {
        List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
        classLoadersList.add(ClasspathHelper.contextClassLoader());
        classLoadersList.add(ClasspathHelper.staticClassLoader());

        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .setScanners(new SubTypesScanner(), new ResourcesScanner(), new TypeAnnotationsScanner())
                .setUrls(ClasspathHelper.forPackage("br.com.hvsystems.modelo"))
                .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("br.com.hvsystems.modelo"))));
        
        Set<Class<? extends Model>> allClasses = reflections.getSubTypesOf(Model.class);
        
        Object[] classes = (Object[]) allClasses.toArray();
        for (Class<?> c: allClasses) {
            System.out.println("Nome da Classe: " + c.getSimpleName());
            if (c.getSimpleName().equalsIgnoreCase(tabela)) {
                try {
                    return c.newInstance();
                } catch (InstantiationException ex) {
                    System.out.println("InstantiationException: ");
                    Logger.getLogger(ActiveEntity.class.getName()).log(Level.SEVERE, null, ex);
                    
                } catch (IllegalAccessException ex) {
                    System.out.println("IllegalAccessException: ");
                    Logger.getLogger(ActiveEntity.class.getName()).log(Level.SEVERE, null, ex);
                    
                }
            }
        }
        return null;
    }


Banco.java
package br.com.hvsystems.modelo;

import org.javalite.activejdbc.Model;
import org.javalite.activejdbc.annotations.DbName;
import org.javalite.activejdbc.annotations.Table;

@Table("Banco")
public class Banco extends Model {
    }

Exception
HvHealthServer - Server - run(), erro: 
failed to determine Model class name, are you sure models have been instrumented?


Igor Polevoy

unread,
Apr 20, 2015, 1:11:14 AM4/20/15
to activejd...@googlegroups.com
Are   you instrumenting the models before executing code? 

tx

Hugo Alexandre Aguera Viana

unread,
Apr 21, 2015, 7:38:44 PM4/21/15
to activejd...@googlegroups.com
Hello Igor, I'm using maven. The following pom.xml

ServerFx
<?xml version="1.0" encoding="UTF-8"?>
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>br.com.hvsystems</groupId>
    <artifactId>HvSystemsServer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <organization>
        <!-- Used as the 'Vendor' for JNLP generation -->
        <name>HvSystems</name>
    </organization>
    
    <dependencies>
        <dependency>
            <groupId>com.panemu</groupId>
            <artifactId>tiwulfx</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.180</version>
        </dependency>
        <dependency>
            <groupId>org.javalite</groupId>
            <artifactId>activejdbc-instrumentation</artifactId>
            <version>1.4.10</version>
        </dependency>
        <dependency>
            <groupId>org.javalite</groupId>
            <artifactId>activejdbc</artifactId>
            <version>1.4.10</version>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.9</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.javalite</groupId>
                <artifactId>activejdbc-instrumentation</artifactId>
                <version>1.4.10</version>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <meminitial>256m</meminitial>
                    <maxmem>512m</maxmem>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14.1</version>
                <configuration>
                    <reportFormat>brief</reportFormat>
                    <trimStackTrace>true</trimStackTrace>
                    <useFile>false</useFile>
                    <includes>
                        <include>**/*Spec*.java</include>
                        <include>**/*Test*.java</include>
                    </includes>
                    <excludes>
                        <exclude>**/helpers/*</exclude>
                        <exclude>**/*$*</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


Client
<?xml version="1.0" encoding="UTF-8"?>
    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.hvsystems</groupId>
    <artifactId>HvSystems</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>HvSystems</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>br.com.hvsystems.HvHealthCore</mainClass>
    </properties>

    <organization>
        <!-- Used as the 'Vendor' for JNLP generation -->
        <name>HV Systems</name>
    </organization>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeScope>system</excludeScope>
                            <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/../bin/javafxpackager</executable>
                            <arguments>
                                <argument>-createjar</argument>
                                <argument>-nocss2bin</argument>
                                <argument>-appclass</argument>
                                <argument>${mainClass}</argument>
                                <argument>-srcdir</argument>
                                <argument>${project.build.directory}/classes</argument>
                                <argument>-outdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-outfile</argument>
                                <argument>${project.build.finalName}.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-cli</id>
                        <goals>
                            <goal>exec</goal>                            
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <commandlineArgs>${runfx.args}</commandlineArgs>
                        </configuration>
                    </execution>
                </executions>  
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <meminitial>256m</meminitial>
                    <maxmem>512m</maxmem>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14.1</version>
                <configuration>
                    <reportFormat>brief</reportFormat>
                    <trimStackTrace>true</trimStackTrace>
                    <useFile>false</useFile>
                    <includes>
                        <include>**/*Spec*.java</include>
                        <include>**/*Test*.java</include>
                    </includes>
                    <excludes>
                        <exclude>**/helpers/*</exclude>
                        <exclude>**/*$*</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.javalite</groupId>
                <artifactId>activejdbc-instrumentation</artifactId>
                <version>1.4.10</version>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>            
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>unknown-jars-temp-repo</id>
            <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
            <url>file:${project.basedir}/lib</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>com.panemu</groupId>
            <artifactId>tiwulfx</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.180</version>
        </dependency>
        <dependency>
            <groupId>org.jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>GeoIPService</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.javalite</groupId>
            <artifactId>activejdbc</artifactId>
            <version>1.4.10</version>
        </dependency>
        <dependency>
            <groupId>org.javalite</groupId>
            <artifactId>activejdbc-instrumentation</artifactId>
            <version>1.4.10</version>
        </dependency>
    </dependencies>
     
</project>

Igor Polevoy

unread,
Apr 22, 2015, 2:45:32 AM4/22/15
to activejd...@googlegroups.com
Hugo, you do not need instrumentation plugin as a dependency.  You can remove this: 
        <dependency>
            <groupId>org.javalite</groupId>
            <artifactId>activejdbc-instrumentation</artifactId>
            <version>1.4.10</version>
        </dependency>


However, this is not the problem. Please, ensure that you are not compiling classes with your IDE after instrumentation. 
In any case, you must: 

1. Compile 
2. Instrument
3. Execute

If you compile again after step 2, you will erase instrumentation. 

tx 
Reply all
Reply to author
Forward
0 new messages