jvm-profiling-tools / perf-map-agent

A java agent to generate method mappings to use with the linux `perf` tool
GNU General Public License v2.0
1.65k stars 260 forks source link

Could not find or load main class net.virtualvoid.perf.AttachOnce #17

Closed stepancheg closed 9 years ago

stepancheg commented 9 years ago
# ./bin/perf-java-top 19835
Error: Could not find or load main class net.virtualvoid.perf.AttachOnce

scripts expects attach-main.jar to be found in out dir, while it is in the project root dir.

jrudolph commented 9 years ago

@stepancheg I recently changed the directory structure. Can you try to git clean the project and then run cmake . && make again? This should put build artifacts into out.

stepancheg commented 9 years ago

I did build in clean checkout, it didn't help.

Problem must be in cmake. Seems like CMake 2.8 which I use doesn't understand OUTPUT_DIR option. I bet you have newer version?

jrudolph commented 9 years ago

Not sure about that:

> cmake --version
cmake version 2.8.12.2
jrudolph commented 9 years ago

I'm on Ubuntu 14.04.3 btw.

jerrinot commented 9 years ago

I'm having the same problem with cmake version 2.8.11 on CentOS 7.0.1406

jrudolph commented 9 years ago

Is "the same problem", that attach-main.jar gets copied to the root directory of the project?

jerrinot commented 9 years ago

indeed

jrudolph commented 9 years ago

Can you try if adding this line to CMakeLists.txt helps:

set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${OUTDIR})
jerrinot commented 9 years ago

Yep, it seems it did the trick! Thanks!

[simulator@localhost perf-map-agent]$ git diff CMakeLists.txt 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8bcebbf..98e5832 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,7 @@ project (perf-map-agent)
 # Binaries (agent libperfmap.so and attach-main.jar) will end up in ./out
 set(OUTDIR ${PROJECT_BINARY_DIR}/out)
 set(LIBRARY_OUTPUT_PATH ${OUTDIR})
+set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${OUTDIR})

 find_package(JNI)
 if (JNI_FOUND)
jrudolph commented 9 years ago

Cool, thanks for verifying.

jerrinot commented 9 years ago

no problem. Thanks for your work on this!

donsi commented 7 years ago

FYI I got the same error Error: Could not find or load main class net.virtualvoid.perf.AttachOnce

In my case it was due to the fact that the user that was being su'ed to (ie the user that owned the java process being attached to) did not have access to the directory where the software was installed.

sattishv commented 6 years ago

Hi Team,

Even i got the same error "Error: Could not find or load main class net.virtualvoid.perf.AttachOnce" I could see the files attach-main.jar and libperfmap.so in out directory. but still it fails. I am running the attach command as user who owns the java process inside the docker container java -cp attach-main.jar:$JAVA_HOME/lib/tools.jar net.virtualvoid.perf.AttachOnce 5063

Any help greatly appreciated.

Thanks Sattish

tekumara commented 6 years ago

@sattishv see issue #50 for tips on running inside Docker.

Liron24 commented 5 years ago

@donsi I think I have the same issue. I have tomcat running my Java app and I get the error. How did you resolve your issue?

donsi commented 5 years ago

@Liron24 my issue was that the user that the java process (eg tomcat) was running under did not have access to the directory where perf-map-agent was installed. Ensuring that the user had access fixed the problem for me.

Liron24 commented 5 years ago

@donsi thank you. Now I'm getting the following: Exception in thread "main" java.lang.UnsupportedClassVersionError: net/virtualvoid/perf/AttachOnce : Unsupported major.minor version 52.0 Did you come across such error?

donsi commented 5 years ago

Sorry @Liron24 I don't recall getting that error.

alex-dukhno commented 5 years ago

Hi @Liron24, Seems like you build perf-map-agent with Java 8 and run your tomcat application on Java prior this version. I suggest you check your java versions and align them. However, I don't remember required Java version for map-agent though. Hope it helps.

Liron24 commented 5 years ago

@alex-dukhno thank you for the response, do you know how can change the Java version for the perf-map-agent?

alex-dukhno commented 5 years ago

@Liron24 I haven't built perf-map-agent in a while, but I assume that you can change Java with JAVA_HOME as pointed in Readme file build section. You need to install your's tomcat JDK version on your machine and change JAVA_HOME. Or, if it is possible, check out git repo onto your's tomcat machine and build agent their.

Liron24 commented 5 years ago

@alex-dukhno Thank you!