ActiveJpa/activejpa

AgentLoadException: Agent JAR not found or no Agent-Class attribute

dzcdhj opened this issue · 15 comments

Caused by: com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:117)
at org.activejpa.enhancer.ActiveJpaAgentLoader.loadAgent(ActiveJpaAgentLoader.java:40)

windwos xp with jdk 1.7

ActiveJPA reads MANIFEST entries at runtime. I guess the way you are building the application, the manifest entries are lost. For instance, if you create a FAT jar, the manifest entries will be lost.

Let me know if that's not the case.

Hi Ganeshs,
I ran into a similar problem while trying to check out your project.

Caused by: com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:117)
at org.activejpa.enhancer.ActiveJpaAgentLoader.loadAgent(ActiveJpaAgentLoader.java:40)

I can confirm the manifest file has not been altered in anyway. The problem appears to be

codeSource.getLocation().toURI().getPath() is returning null. I assume this is because there is no path to a non-file location.

hi Ganeshs
I ran into a similar problem while trying to check out your project.
I want to konw whether you project can run ? and i can‘t find the manifest on your project.

@Hillrunner2008 / @zzia309 , Thanks for using ActiveJpa. ActiveJpa is used in our production apps that handle over 60 million users and its quite stable.

ActiveJpa loads the javaagent at runtime. It identifies the agent jar by locating the physical location of the jar file using,

codeSource.getLocation().toURI().getPath()

It would be really helpful to debug if you can let me know the below,

  1. How is your project bundled?. Do you compress all the dependencies of your project into one single jar?
  2. How do you start your project?. The java command with arguments that you use to start the project will help
  3. Are you using any container like tomcat, jboss or frameworks like Play, Dropwizard etc.. ?

I would really appreciate if you can confirm whether you can run the sample application located at https://github.com/ActiveJpa/activejpa/tree/master/activejpa-examples.

  1. I use maven as a bulid tool
  2. i don not use tomcat but jetty run, which is a plugin for eclipse
  3. the demo i down from spring and i just add the activeJpa depency in the pom.xml and write a custom class named customListener and config it in the spring-config.xml

I want to kown which the agent jar is ? what is it's name? is management-agent(in the jdk )

I have find the bug !
the experssion 'codeSource.getLocation().toURI().getPath()' may be right or error in different environment
in win7 jdk7
the result if codeSource.getLocation().toURI().getPath() is /C:/Users/Administrator/.m2/repository/org/activejpa/activejpa-core/0.2.3-SNAPSHOT/activejpa-core-0.2.3-SNAPSHOT.jar
but the right path is C:/Users/Administrator/.m2/repository/org/activejpa/activejpa-core/0.2.3-SNAPSHOT/activejpa-core-0.2.3-SNAPSHOT.jar
you can read this post
http://stackoverflow.com/questions/11613100/how-to-get-the-path-of-a-directory-where-my-running-jar-file-is

there is my code
public void loadAgent() {
logger.info("dynamically loading javaagent");
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
int p = nameOfRunningVM.indexOf('@');
String pid = nameOfRunningVM.substring(0, p);

    try {
        VirtualMachine vm = VirtualMachine.attach(pid);
        CodeSource codeSource = ActiveJpaAgent.class.getProtectionDomain().getCodeSource();
        //begin
        File file = new File(codeSource.getLocation().toURI().getPath());
        String path = file.getAbsolutePath();
        vm.loadAgent(path, "");
        //end
        vm.detach();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

my english is bad, i wish you can understand me.

Thanks for the analysis. Looks like a problem in windows OS. I have tested this in mac and linux. If you have already figured out a solution that addresses all the OSes, can you submit a patch?

ok
i will commit later today!

yanghui_java@163.com

From: Ganesh Subramanian
Date: 2014-09-04 16:46
To: ActiveJpa/activejpa
CC: zzia309
Subject: Re: [activejpa] AgentLoadException: Agent JAR not found or no Agent-Class attribute (#25)
Thanks for the analysis. Looks like a problem in windows OS. I have tested this in mac and linux. If you have already figured out a solution that addresses all the OSes, can you submit a patch?
¡ª
Reply to this email directly or view it on GitHub.

Thanks,zzia309

I want to konw how many users who used it ?

@zziahui, its been used in production at web scale. I can name a couple of
them, www.flipkart.com, www.hightail.com, www.olacabs.com.

-Ganesh

On Thu, Apr 30, 2015 at 12:11 PM, zziahui notifications@github.com wrote:

I want to konw how many users who used it ?


Reply to this email directly or view it on GitHub
#25 (comment).

Workaround:
String OS = System.getProperty("os.name");
String path = codeSource.getLocation().toURI().getPath();
if(path != null && path.startsWith("/") && OS.startsWith("Windows")){
path = path.substring(1);
}
vm.loadAgent(path, "");

I got the same issue, until we got the official patch, one way to workaround is create a class org.activejpa.enhancer.ActiveJpaAgentLoaderImpl (override the current implement) - confirmed working on Windows with ActiveJPA 1.1.0 and 1.1.1
(and using the code above from @stevexu01 )

package org.activejpa.enhancer;

import com.sun.tools.attach.VirtualMachine;

import java.lang.management.ManagementFactory;
import java.security.CodeSource;

public class ActiveJpaAgentLoaderImpl {
    public ActiveJpaAgentLoaderImpl() {
    }

    public static void loadAgent() {
        String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
        int p = nameOfRunningVM.indexOf(64);
        String pid = nameOfRunningVM.substring(0, p);

        try {
            VirtualMachine vm = VirtualMachine.attach(pid);
            CodeSource codeSource = ActiveJpaAgent.class.getProtectionDomain().getCodeSource();
            String OS = System.getProperty("os.name");
            String path = codeSource.getLocation().toURI().getPath();
            if (path != null && path.startsWith("/") && OS.startsWith("Windows")) {
                path = path.substring(1);
            }
            vm.loadAgent(path, "");
            vm.detach();
        } catch (Exception var5) {
            throw new RuntimeException(var5);
        }
    }
}

This may not be caused by loading classes, that is, your application running in docker needs to run inside the monitor.