How to using Jetty source code start web app - java

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.

Related

java agent Instrumented class file not reflected on PCF

Need some help.
We have a custom java agent written using javaassist that instruments Logger file from logback for info method. The agent works as standalone program from command line, when used with -javaagent option, while running target app/class. It also works if a sample maven project is created in Eclipse and executed by Providing run configuration having -javaagent in run configuration.
Premain is called - transformer is called - instruments the class file - prints the log as updated using instrumentation.
While pushing on PCF:
The agent in packaged into spring-boot app binary, under MyApp.jar\BOOT-INF\classes\ This is very Simple Hello Program with one controller
Issue is
Premain is called - transformer is called - instruments the class file, However does not print the log as updated using instrumentation.
Do we need any specific configuration to get this instrumented file back to PCF?
Appreciate your inputs/queries.
Here is manifest.yml
applications:
- name: KedarTestApp
memory: 2G
disk_quota: 1G
instances: 1
path: target/Hello-0.0.1-SNAPSHOT.jar
env:
SPRING_PROFILES_ACTIVE : "dev"
JAVA_OPTS: -javaagent:BOOT-INF/classes/Agent.jar
Dev Env:
JDK8, WIndows 10, cf version 6.26, cf cli
Posting in case anyone needs it for refrence :)
If the instrumentation library is not on the class path - PCF wont show error/warning,but also wont instrument your classes.
The instrumentation libraries will be part of your binary, but are not loaded when PCF starts the app with org.springframework.boot.loader.JarLauncher.
You will need to provide the path to instrumentation libraries as part of -cp argument on your manifest's command: option.

Running Jenkins from command line vs as Windows service

I ran into a very strange issue. I need to configure proxy in my Jenkins to be able to access SVN repository in one of the jobs. I have done so in 2 ways:
Started Jenkins from command line with the required arguments
Started Jenkins as Windows service while the arguments are defined in the jenkins.xml file.
Starting from command line:
C:\>java -DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP
="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=312
8 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar %JENKINS_HOME%\jenkins
.war
Starting as service (below is the jenkins.xml contents):
<executable>java</executable>
<arguments>-DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar "%JENKINS_HOME%\jenkins.war"</arguments>
So that's exactly the same. The issue however is that when I am using command line to start Jenkins, proxying works fine. But when I start Jenkins as service, the repo (through the proxy) cannot be accessed and I get this error message:
Please note that if I look at the System Properties in System Information section, the proxy parameters appear the same in both cases so the configuration is being applied properly:
Apparently there is a difference in how Jenkins starts up depending on how it was started (command line or windows service). What reinforces this assumption is that I see that some log files are only being written when I start Jenkins as a service but not when I start it from command line. I am talking about these log files:
jenkins.wrapper.log
jenkins.out.log
What do I need to do differently to get the same result from Jenkins as service as I do when I start it from command line? What configuration am I missing?
Jenkins as a Windows service doesn't run under your current user but under the LocalSystem Account by default.
See MSDN: Using the LocalSystem Account as a Service Logon Account and SO: The difference between the 'Local System' account and the 'Network Service' account? for the implications.

Jetty and Java Agent Don't Work Using Logging

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.

Remote debugging in eclipse issue

echo "LSE Parser v1.0"
javac -d ../build -classpath ../build:${MY_CLASSPATH} *.java
cd ../build
jar -cf ../lib/lse.jar .
cd ../src
The above is my build script for a java application. there is a serperate run file which has all the CLASSPATH defined and runs the application.
I am trying to remote debug the application on eclipse but facing issues. The code is sitting on unix server host. i've closely followed instructions about debug configurations... for eclipse.
This is what I'm doing:
I locate my build (above) in putty terminal and execute with . ./build
I type java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
On eclipse debug config... I enter a random name, project is lse, gave correct host and gave port number as 9999. checked termination of remote VM. When I click debug, it does not stop on the breakpoint.
NOTE: in the project "lse" are 3 .java source that the application uses. the "lse" project has only src content, however in the Unix host it has all the lib, scripts, config folder.
Please can someone tell me what I'm doing wrong. after step 2, I managed to get
Listening for transport dt_socket at address: 9999
then after step 3, I get some messages on putty
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is server,
because you are running on a server-class machine.
....
and see on eclipse a terminated status on debug mode. java hotspot server [host bla bla]
I imagine you solved this by now...but looks like you forgot to provide the name of the class for java to run. If your main method was in a source file like foo/Bar.java, then you would need to add foo.Bar to your java line. Something like:
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999 foo.Bar
You might also consider adding -g to your javac to generate debug info.
You could avoid all (or most) of this pain if your source was in the IDE that you're trying to debug with...

Additional debug option for runnable jar using command prompt

I know that the java -jar filename.jar is used for executing the jar file using command prompt, but could anyone please explain the following command:
java -jar filename.jar -debug
What is the exact use of the -debug in the above command?
This is not a flag for the Java Interpreter (as those should be passed before the actual class/jar).
If you execute the command-line you posted above, this will launch your filename.jar-files main class and give it's main(String[] args)-method the -debug-parameter as the second argument in the args-array.
But, there is (or was) also the -debug flag from older Java versions, which has been replaced by the -Xdebug flag. The (certainly old) manpage states that:
-debug Allows the Java debugger - jdb(1) - to attach
itself to this java session. When -debug is
specified on the command line java displays a
password that must be used when starting the
debugging session.
If a Java application is launched with the debug flag, remote-debuggers can attach to the running application and you can (for example) monitor it using JConsole

Categories

Resources