I'm trying to run Jetty with java agent instrumentation.
I'm using the following command:
java -javaagent:%JETTY_HOME%/lib/ext/aspectjweaver-1.8.9.jar -jar %JETTY_HOME%/start.jar
It works as expected.
But, when adding a logging module to Jetty (java -jar %JETTY_HOME%/start.jar --add-to-start log4j) and then start the Jetty server it runs without instrumentation at all.
Note: I was able to start the agent with instrumentation when I used the full output of '--dry-run' command.
Any idea why the agent wasn't loaded when running the standard jetty startup command with a logging module?
Thanks,
Dror
Run java -jar start.jar --list-config from your jetty base.
It's likely that your configuration is triggering an --exec call which will fork a new JVM.
The -javaagent command would not be passed forward to that new JVM.
Related
I have the following problem after executing the Main class directly
ERROR : No enabled jetty modules found!
INFO : ${jetty.home} = /Users/zhangsan/git_repo/servlet-container/jetty.project
INFO : ${jetty.base} = /Users/zhangsan/git_repo/servlet-container/jetty.project
ERROR : Please create and/or configure a ${jetty.base} directory.
Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs]
java -jar $JETTY_HOME/start.jar --help # for more information
I do not want to start with the start.jar file. What do I do
You can generate the full JVM command line used to start jetty with the dry-run command:
java -jar $JETTY_HOME/start.jar --dry-run
This will give you all the options and classpath that is required to run Jetty with your current configuration in your jetty-base directory.
With this you can enter the configuration into your intellij run configurations options for Main.java. But this is not recommended, if any configuration changes in the jetty-base then the JVM command line options required will change as well.
Perhaps you should look into running with remote JVM debug as described in https://github.com/eclipse/jetty.project/issues/8114, or even switching to using embedded Jetty.
I have a spring boot application with embedded tomcat in it. I need to run this application in Jenkins the problem is that the build goes into an infinite loop.
javaw -jar myjar.jar
does the same thing as mentioned above. It was mentioned somewhere in SO that if we append start with the above mentioned code it will work.
start javaw -jar myjar.jar
the issue with this is that Jenkins build are completed now, but the application doesnt run.
Is there any way i can solve this issue ?
Note:
Jenkins and salve is running on windows.
I want to run a JAX-RS 2.0 (Jersey) application on an embedded Tomcat (7). But I have not found an example or documentation about it.
How can I set up Tomcat 7 programatically and add a Servlet wrapping a JAX-RS application to it?
If you want to start/stop Tomcat from Java environment, look at its startup scripts to see which classes are invoked. It's actually not that complex; I do this from my IntelliJ all the time. My IntelliJ startup config looks like this:
Main Class: org.apache.catalina.startup.Bootstrap
VM parameters: -ea -cp $CLASSPATH:/path/to/tomcat/bin/bootstrap.jar -Dcatalina.base="/path/to/tomcat" -Dcatalina.home="/path/to/tomcat" -Djava.io.tmpdir="/path/to/tomcat/temp" -noverify -Xmx400M -XX:MaxPermSize=400M
Program parameters: start
Working directory: /path/to/tomcat
If you want to stop Tomcat gracefully, the only different thing is program parameters, which is stop.
I want to measure the code coverage of integration tests using the JaCoCo and Sonar tools.
For that, I start my Tomcat 5.5 configured with the JaCoCo agent in order to get the dump file from JaCoCo.
Thus, I set the JAVA_OPTS for that:
set JAVA_OPTS=-Xrs -XX:MaxPermSize=256m -XX:PermSize=256m -XX:NewRatio=3 -Xms512m -Xmx1024m -XX:+UseParallelGC -javaagent:C:\dev\servers\jacoco-agent.jar=destfile=C:\dev\servers\jacoco.exec,append=true,includes=my.application.*
When I start Tomcat, the C:\dev\servers\jacoco.exec file is generated, but no data is filled.
Is there something I forgot in the configuration of my server?
Regards.
I realize this may not have been an option 2 years ago when this question was asked, but presently you have some other options available to fetch the JaCoCo execution data without shutting down Tomcat (or any JVM instrumented with the JaCoCo java agent).
First take a look at the current documentation for the JaCoCo Java Agent: http://www.eclemma.org/jacoco/trunk/doc/agent.html
You can use the output=tcpserver option on the JaCoCo agent to have the Java agent listen for commands. You can set address=* to have the tcpserver listen on all interfaces, and you can set the port=6300 argument to choose the port where the tcpserver should listen.
Through the tcpserver the JaCoCo java agent can be instructed to send you the data whenever you ask for it.
If your JVM is currently exposing JMX you have another option which you can utilize without opening additional ports. By setting the jmx=true option the JaCoCo java agent exposes an MBean which you can interact with.
If you are using maven you can take a look at the plugin I recently wrote in order to gather JaCoCo data from remote JVM's while running. The project for the plugin is located at:
https://github.com/mattcj/jacocotogo
As far as I remember - file would be populated during shutdown of Tomcat.
Besides the maven solution, you can also consider https://www.eclemma.org/jacoco/trunk/doc/cli.html
Basically, you start your service on the remote machine with the javaagent option like (you can change the port number and omit includes if you want to have coverage for all of the classes):
-javaagent:/tmp/jacocoagent.jar=port=36320,destfile=jacoco-it.exec,output=tcpserver,includes=a.b.c.d.*”
Then connect to the remote machine by providing remote host address or open a tunnel to the remote machine. The following example assumes I have set up a port forwarding between local host's 36320 and remote host's 36320
java -jar jacococli.jar dump --port 36320 --destfile /tmp/jacoco-it.exec
If you have multiple .exec files, you need to merge them:
java -jar jacococli.jar merge /tmp/jacoco-it-1.exec /tmp/jacoco-it-2.exec --destfile /tmp/merge
Then generate the html report (path1 can be a path to the jar file or the class files folder)
java -jar jacococli.jar report /tmp/jacoco-it.exec --classfiles path1 --sourcefiles path2 --html /tmp/report
I am trying to use the NSSM - the Non-Sucking Service Manager to run Jetty that is included with Solr as a Windows Service. Everything works fine by placing Java.exe in my C:\solr folder and setting up NSSM by pointing to this Java.exe along with the following parameters -Dsolr.solr.home=C:/solr -jar start.jar
You can also run C:\solr\java.exe -Dsolr.solr.home=C:/solr -jar C:/solr/start.jar from the command line without installing the service as a test which works fine.
If I leave Java.exe in the System32 folder though, things will not work and I get a java.lang.ClassNotFoundException for org.mortbay.xml.XmlConfiguration.
I can of course run C:\solr\java -Dsolr.solr.home=C:/solr -jar C:/solr/start.jar as well since Java is in my PATH.
If seems like I need an additional classpath option or something but I don't know?
I ended up using the following in the arguments for NSSM: -Dsolr.solr.home=C:/solr/ -Djetty.home=C:/solr/ -Djetty.logs=C:/solr/logs/ -cp C:/solr/lib/*.jar;C:/solr/start.jar -jar C:/solr/start.jar