Bug 64680 - Jmeter failed to start with the Prometheus JMX agent when run not from $JMETER_HOME/bin
Summary: Jmeter failed to start with the Prometheus JMX agent when run not from $JMETE...
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.1.1
Hardware: All All
: P2 normal (vote)
Target Milestone: JMETER_5.4
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2020-08-20 05:34 UTC by sergiy.iampol
Modified: 2020-09-02 14:16 UTC (History)
1 user (show)



Attachments
check on night buid (91.37 KB, image/jpeg)
2020-08-28 05:52 UTC, sergiy.iampol
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sergiy.iampol 2020-08-20 05:34:10 UTC
Trying configure Prometheus JMX agent for Jmeter but faced following issue - when I start Jmeter outside of $JMETER_HOME/bin folder - it fails with an error:

java.lang.Throwable: Could not access null/lib
        at org.apache.jmeter.NewDriver.<clinit>(NewDriver.java:105)
java.lang.Throwable: Could not access null/lib/ext
        at org.apache.jmeter.NewDriver.<clinit>(NewDriver.java:105)
java.lang.Throwable: Could not access null/lib/junit
        at org.apache.jmeter.NewDriver.<clinit>(NewDriver.java:105)
java.lang.ClassNotFoundException: org.apache.jmeter.JMeter
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at org.apache.jmeter.NewDriver.main(NewDriver.java:250)
JMeter home directory was detected as: null

null- is because I run from / , and JMeter is set to parent dir

Launch command:

java -Dcom.sun.management.jmxremote.port=12021 -Dcom.sun.management.jmxremote.rmi.port=12021 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dgroovy.use.classvalue=true -javaagent:/apps/injector/apache-jmeter/bin/jmx_prometheus_javaagent-0.13.0.jar=8778:/apps/injector/apache-jmeter/bin/prometheus_config.yaml -jar /apps/injector/apache-jmeter/bin/ApacheJMeter.jar -n -t /apps/injector/apache-jmeter/extras/Test.jmx

Same command works fine in case I run it from $JMETER_HOME/bin folder.

Running a Jmeter with -javaagent option defined - set JMeter home directory as a parent dir for the dir I trying to run from.

JMETER_HOME env var is defined and both JMETER_HOME and JMETER_HOME/bin added to PATH. And I can run Jmeter with the above command from any path when removing -javaagent option from the original command.

Tried also -d/--homedir Jmeter options - but this didn't help.

How can I make Jmeter to be compatible with Prometheus agent and to be run from any path?

p.s. tried on both Linux/Win.
Comment 1 Sunny Agrawal 2020-08-21 03:02:06 UTC
I guess the command used for starting the test is not right. We need to follow below commands to run the jmx. i see your command has a unwanted extension '-jar ApacheJmeter.jar'

jmeter -n -t my_test.jmx -l log.jtl

Reference:- https://jmeter.apache.org/usermanual/get-started.html

Thanks
Comment 2 sergiy.iampol 2020-08-21 07:28:24 UTC
>>jmeter -n -t my_test.jmx -l log.jtl

jmeter here is a bat/sh script that set all parameters and start Jmeter itself. But finally it just call the command I wrote.

Originally it's smth like that:
"$JAVA_HOME/bin/java" $ARGS $JVM_ARGS $JMETER_OPTS -jar "$PRGDIR/ApacheJMeter.jar" "$@"

So your command would be translated into:
"$JAVA_HOME/bin/java" $ARGS $JVM_ARGS $JMETER_OPTS -jar "$PRGDIR/ApacheJMeter.jar" "-n -t my_test.jmx -l log.jtl"

We used jmeter.sh (adjusted to our needs). And I got the original error launching it with the jmeter.sh script.

I've specified real java command with all options just for better understanding of what java options were used
Comment 3 Felix Schumacher 2020-08-21 09:37:52 UTC
If you set the env variable JMETER_HOME and use $JMETER_HOME/bin/jmeter to start JMeter, the shell script should do no further processing to guess JMETER_HOME.

Can you try to be more specific on your setup? Where is your installation of JMeter? Is the bin folder still in JMETER_HOME? Which JDK do you use?
Comment 4 sergiy.iampol 2020-08-21 14:48:13 UTC
As I said - it does work without -javaagent option. So the JMETER_HOME defined properly and jmeter.sh can be started from anywhere.
But when I add this option (-javaagent) jmeter home dir is set somehow to the parent (for the current dir) folder. That's why it does work from JMETER_HOME/bin and doesn't work from anywhere else.

As for bin - yes, it's in the JMETER_HOME
JDK - HotSpot 1.8.0.221(121)
Comment 5 sergiy.iampol 2020-08-21 15:13:05 UTC
As I said - it does work without -javaagent option. So the JMETER_HOME defined properly and jmeter.sh can be started from anywhere.
But when I add this option (-javaagent) jmeter home dir is set somehow to the parent (for the current dir) folder. That's why it does work from JMETER_HOME/bin and doesn't work from anywhere else.

As for bin - yes, it's in the JMETER_HOME
JDK - HotSpot 1.8.0.221(121)
Comment 6 Felix Schumacher 2020-08-21 15:26:07 UTC
You could try Java 11 (at least in my local setup it worked).

Can reproduce the error message with Java 8 and will look into it.
Comment 7 Felix Schumacher 2020-08-21 15:36:52 UTC
Another workaround is to add -Djmeter.home=$JMETER_HOME to your command line options.

The problem is, that the addition of the javaagent will add another entry to the classpath on startup. JMeter specifically looks for a classpath with one entry, only (there is an exception for macos, though). If the classpath on startup has more entries, it will look fot the system property jmeter.home.
Comment 8 Felix Schumacher 2020-08-21 15:44:31 UTC
I added a fallback, to use JMETER_HOME, if the other detection mechanisms failed. 

Could you test the next build/nightly?

commit 20ba58d0c0273d1857a3c1b614d32617faf7f7ce
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Fri Aug 21 17:41:58 2020 +0200

    Fall back to JMETER_HOME on startup to detect JMeter's installation directory
    
    Bugzilla Id: 64680
---
 src/launcher/src/main/java/org/apache/jmeter/NewDriver.java | 3 +++
 xdocs/changes.xml                                           | 1 +
 2 files changed, 4 insertions(+)
Comment 9 Felix Schumacher 2020-08-21 15:44:31 UTC
I added a fallback, to use JMETER_HOME, if the other detection mechanisms failed. 

Could you test the next build/nightly?

commit 20ba58d0c0273d1857a3c1b614d32617faf7f7ce
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Fri Aug 21 17:41:58 2020 +0200

    Fall back to JMETER_HOME on startup to detect JMeter's installation directory
    
    Bugzilla Id: 64680
---
 src/launcher/src/main/java/org/apache/jmeter/NewDriver.java | 3 +++
 xdocs/changes.xml                                           | 1 +
 2 files changed, 4 insertions(+)
Comment 10 sergiy.iampol 2020-08-21 16:02:35 UTC
-Djmeter.home - works for me. Thanks a lot!!

Will try next build/nightly next week
Comment 11 Philippe Mouawad 2020-08-27 13:44:47 UTC
(In reply to sergiy.iampol from comment #10)
> -Djmeter.home - works for me. Thanks a lot!!
> 
> Will try next build/nightly next week

Hello,
Did you have a chance to try nightly build ? 
https://ci.apache.org/projects/jmeter/nightlies/
Thank you for your feedback.
Regards
Comment 12 sergiy.iampol 2020-08-28 05:52:59 UTC
Created attachment 37410 [details]
check on night buid
Comment 13 sergiy.iampol 2020-08-28 05:53:22 UTC
Trier on LATEST (r1830-b2d487c6fb3d9ba31b651e1e0c8a1eac05478f5d). Same problem exists.
JMETER_HOME is set but once I run with prometheus agent - it treated as parent dir for the dir I'm running from.
See attachment
Comment 14 Felix Schumacher 2020-08-28 07:57:30 UTC
There was another fall-back in place, which took preference over JMETER_HOME. That fall-back came into life, when you switched from the root directory to some other directory :) I only tested your exact description. My fault.

Could you please test again?

commit fd8b99411eb442df44cd0d779e0c7505c5a6adc1
AuthorDate: Fri Aug 28 09:46:53 2020 +0200

    Fall back to JMETER_HOME on startup (even more fall-back)
    
    Use JMETER_HOME as a fall back even before trying user.dir.
    
    Relates to 20ba58d0c0273d1857a3c1b614d32617faf7f7ce
    Bugzilla Id: 64680
---
 src/launcher/src/main/java/org/apache/jmeter/NewDriver.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 15 sergiy.iampol 2020-09-02 14:16:16 UTC
works with r1831-fd8b99411eb442df44cd0d779e0c7505c5a6adc1
Comment 16 The ASF infrastructure team 2022-09-24 20:38:20 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/5388