tomcat jvm arguments lost - bash

I want to run tomcat with a javaagent.
setenv.sh:
export JAVA_HOME=/home/ggfan/1-install/java/jdk1.8.0_271
export CATALINA_OPTS="${CATALINA_OPTS} -javaagent:/home/ggfan/2-work/centuari-space/jdbc-leak-detector/target/jdbcld.jar=/home/ggfan/3-tmp/logs/jdbcld,INFO,org.apache.commons.dbcp.PoolingDataSource\$PoolGuardConnectionWrapper"
call startup.sh, seems tomcat picked it correctly:
[ggfan#localhost bin]$ ./startup.sh
Using CATALINA_BASE: /home/ggfan/1-install/apache-tomcat-8.5.64
Using CATALINA_HOME: /home/ggfan/1-install/apache-tomcat-8.5.64
Using CATALINA_TMPDIR: /home/ggfan/1-install/apache-tomcat-8.5.64/temp
Using JRE_HOME: /home/ggfan/1-install/java/jdk1.8.0_271
Using CLASSPATH: /home/ggfan/1-install/apache-tomcat-8.5.64/bin/bootstrap.jar:/home/ggfan/1-install/apache-tomcat-8.5.64/bin/tomcat-juli.jar
Using CATALINA_OPTS: -javaagent:/home/ggfan/2-work/centuari-space/jdbc-leak-detector/target/jdbcld.jar=/home/ggfan/3-tmp/logs/jdbcld,INFO,org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
Tomcat started.
however, from tomcat log:
24-Sep-2021 15:45:04.437 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -javaagent:/home/ggfan/2-work/centuari-space/jdbc-leak-detector/target/jdbcld.jar=/home/ggfan/3-tmp/logs/jdbcld,INFO,org.apache.commons.dbcp.PoolingDataSource
inner class name after '$' sign get lost and the real argument received by my javaagent is the incomplete one.
what is wrong?
I am running with tomcat Apache Tomcat/8.5.64 on fedora 31

In order to split CATALINA_OPTS into words an pass them as arguments to java, the catalina.sh script uses eval:
eval exec "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
...
this obviously performs variable expansion on $PoolGuardConnectionWrapper. To prevent this escape the dollar sign twice:
export CATALINA_OPTS="${CATALINA_OPTS} ...PoolingDataSource\\\$PoolGuardConnectionWrapper"

Related

JMX connection to Springboot get connection refused

I am using springboot's sample project from: https://github.com/spring-guides/gs-spring-boot#run-the-application. This is the command I used to run the built jar file:
java -jar build/libs/gs-spring-boot-0.1.0.jar -
Dcom.sun.management.jmxremote -
Dcom.sun.management.jmxremote.port=12348 -
Dcom.sun.management.jmxremote.authenticate=false -
Dcom.sun.management.jmxremote.ssl=false -
Dcom.sun.management.jmxremote.rmi.port=12348 -
Djava.rmi.server.hostname=192.168.7.119
Then I tried to use jmxterm to connect:
java -jar ~/Downloads/jmxterm.jar -l localhost:12348
But getting connection refused error.
The -Dcom.sun... arguments must come before the -jar thing.jar . Anything after the -jar thing.jar are considered arguments to your application, and are passed into main.

Spring: Why I cant check for spring boot version without an error?

I am follow the guide for setting up spring boot with the following link.
http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#getting-started-installing-the-cli
section 10.2.2
when I type $ spring --version
I receive the error below.
/cygdrive/c/Users/Jesse/Documents/.sdkman/candidates/springboot/current/bin/spring: line 83: [: C:\Program: binary operator expected
Error: Could not find or load main class org.springframework.boot.loader.JarLauncher
You need to set the SPRING_HOME variable.
After setting, SPRING_HOME was not resolving correctly for me even though it was set in windows as a user and a system variable, and was also visible when running export via Git Bash. I ended up replacing the last line in my spring.sh file, essentialy forcing the classpath for the java command:
"${JAVA_HOME}/bin/java" ${JAVA_OPTS} -cp "/drive_letter/dir/to/spring/spring-x.x.x.RELEASE/lib/spring-boot-cli-x.x.x.RELEASE.jar" org.springframework.boot.loader.JarLauncher "$#"

Configuring Jetty 9 + Spring 4 add PropertySource file

How to add External PropertySource file to jetty 9 jetty.xml ?
i use spring annotation and External PropertySource file
#PropertySources({
#PropertySource(name = "arm", value = "${propertySource}")
})
public class SecurityConfig extends WebSecurityConfigurerAdapter {
when I run the application through maven I use paramentr like propertySource:
mvn -DpropertySource=file:/etc/jetty/arm.properties jetty:stop jetty:run
Its work perfect jetty start with /etc/jetty/arm.properties config params.
How to add -DpropertySource=/etc/jetty/arm.properties like a parametn to start jetty ? hoe to configurable jetty.xml ?
I read docs
http://www.eclipse.org/jetty/documentation/current/jetty-xml-usage.html
and add string to jetty.xml :
<SystemProperty name="propertySource" default="file:/etc/jetty/arm.properties"/>
but this does not work, and jetty fail.
The use of <SystemProperty> is to evaluate a named system property and use it in an XML file as a value for whatever thing you are attempting to configure.
There's 2 ways you can accomplish this using the jetty-distribution.
1: Simply use the Java JVM command line to add the property
$ cd /path/to/mybase
$ java -DpropertySource=file:/etc/jetty/arm.properties -jar /path/to/jetty-dist/start.jar
2: Allow the ${jetty.base} to manage the Java JVM properties
In your ${jetty.base} add the following 2 lines to your start.ini
--exec
-DpropertySource=file:/etc/jetty/arm.properties
Then you can just run Jetty normally ...
$ cd /path/to/mybase
$ java -jar /path/to/jetty-dist/start.jar
Bonus: Alternate technique
Since this is Spring, you could probably switch to using a classloader resource instead.
Run this command to enable resources classpath
$ cd /path/to/mybase
$ java -jar /path/to/jetty-dist/start.jar --add-to-start=resources
Then put your properties file in the new ${jetty.base}/resources
Lastly, reference your PropertySources via the Spring classloader resource reference instead.
In your ${jetty.base} add the following 2 lines to your start.ini
--exec
-DpropertySource=file:/etc/jetty/arm.properties
#service jetty9 start
[FAIL] Starting Jetty 9 Servlet Engine: jetty9 failed!
# sudo service jetty9 check
[ ok ] Checking arguments for Jetty:.
. ok
[ ok ] PIDFILE = /var/run/jetty9.pid.
[....] JAVA_OPTIONS = -Xmx256m -Djava.awt.headless=true -Djava.io.tmpdir=/var/cache/jetty9/data -Djava.library.path=/usr/lib -Djetty.home=/usr/share/jetty9 -Djetty.logs=/var/log/jetty9 -Djetty.state=/var/lib/jetty[ ok ty.state.
[ ok ] JAVA = /usr/lib/jvm/java-8-openjdk-amd64/bin/java.
[ ok ] JETTY_USER = jetty.
[ ok ] ARGUMENTS =.
[ ok ] Jetty 9 Servlet Engine is running with pid 23749.
solution 2
add to start.ini line --add-to-start=resourcesc
# sudo service jetty9 start
[warn] Starting Jetty 9 Servlet Engine: jetty9[....] /var/run/jetty9.pid exists, but jetty was not running. Ignoring /var/run/jetty9.pid ... (warning).
failed!
Where can I see the log ?

karaf 3.0.1 not starting up

I'm trying to start karaf 3.0.1 in a solaris box (without internet) but getting the following error:
karaf: Ignoring predefined value for KARAF_HOME
Could not resolve mvn:org.eclipse/org.eclipse.osgi/3.8.2.v20130124-134944
and in karaf.log:
Jun 30, 2014 12:21:09 PM org.apache.karaf.main.Main main
SEVERE: Could not launch framework
java.lang.RuntimeException: Could not resolve mvn:org.eclipse/org.eclipse.osgi/3.8.2.v20130124-134944
at org.apache.karaf.main.util.SimpleMavenResolver.resolve(SimpleMavenResolver.java:59)
at org.apache.karaf.main.Main.createClassLoader(Main.java:315)
at org.apache.karaf.main.Main.launch(Main.java:234)
at org.apache.karaf.main.Main.main(Main.java:171)
the bundles are well in place (system folder) and the org.ops4j.pax.url.mvn.cfg file states:
org.ops4j.pax.url.mvn.repositories=\
file:${karaf.home}/${karaf.default.repository}#id=system.repository, \
file:${karaf.data}/kar#id=kar.repository#multi\
http://repo1.maven.org/maven2#id=central,\
http://repository.springsource.com/maven/bundles/release#id=spring.ebr.release,\
http://repository.springsource.com/maven/bundles/external#id=spring.ebr.external
I've tried running the framework using the three methods (server, service, client) but nothing seems to be working.
my environment is:
KARAF_BASE=/export/home/mehdi/bin/karaf
KARAF_HOME=/export/home/mehdi/bin/karaf
KARAF_ETC=/export/home/mehdi/bin/karaf/etc
KARAF_DATA=/export/home/mehdi/bin/karaf/data
JAVA_HOME=/opt/temp/jre1.7.0_13
I googled a bit and found a workaround which says to add -h 127.0.0.1 to the client script, but still nothing.

Debug jboss app in Intellij idea

I am using intellij idea and jboss server.
When I run it it works fine but when I debug it it gives me:
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
Disconnected from server
What is the problem?
Make sure the jboss vm is running with the parameters Idea shows in Debug dialog - specifically the port number seems incorrect to me.
If you're running on OS X Mountain Lion you could try popping -d64 into the VM options, that seemed to work for me. Not passing the variables, I think, will just prevent you from debugging.
For more information check here.
Unchecking the pass variables didn't work for me. What I ended up doing running the jBOSS separately and using 'Remote jBOSS' configuration in intelliJ.
To make debugging work I ened up adding the following lines to the "standalone.sh"
DEBUG_JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=localhost:62307,suspend=n,server=y "
JAVA_OPTS="${DEBUG_JAVA_OPTS} $JAVA_OPTS"
The value of DEBUG_JAVA_OPTS has to be copy and pasted from IntelliJ dialog box. These lines have to be inserted into the script right after the place where script sets up "JAVA_OPTS"
Update:
Looks like IDE generates a new port number for each project. So you have to edit the standalone.sh file every time you switch project. Hopefully somebody can suggest a fix for it.
Another option might be to comment out the 'if' statement in standalone.conf as below.
Note the first $JAVA_OPTS is added (it is the one passed in from IntelliJ). This way there is no need to remember to change the port number for every project.
#Specify options to pass to the Java VM.
#
#if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="$JAVA_OPTS -Xms64m -Xmx512m -XX:MaxPermSize=256m - Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -Djboss.server.default.config=standalone.xml"
#else
#echo "JAVA_OPTS already set in environment; overriding default settings with val ues: $JAVA_OPTS"
#fi

Resources