ClassNotFoundException while calling a class in main application from java agent extension - classloader

I am running a spring boot application, which has a dependency in pom.xml (i.e., client-library)
A java agent extension is running parallelly with spring boot application. I am trying to call a class in client-library class from a class in java agent extension, which gives class not found exception.
NOTE: If I run same thing in eclipse, it will run properly. I checked in eclipse run configuration, it sets all jar files in class path and invokes the spring boot main class along with extension.
I use Class.forName(pachage_name) to call the client library from java agent extension.
It do not work when deployed through command line, can anyone suggest how to fix class not found exception.
copied boot_inf/lib and boot_inf/classes from generated jar and pasted in a folder and set in classpath and invoked main class. App runs properly. But I want to run it as a java -jar only hence want to fix class not found exception.
java -javaagent:"opentelemetry-javaagent-1.15.0.jar" -Dotel.resource.attributes=***** -Dotel.service.name=**** -Dotel.traces.exporter=**** -Dotel.metrics.exporter=**** -Dotel.javaagent.enabled=true -Dcontrast.agent.java.standalone_app_name=***** -Dotel.javaagent.extensions="otel-agent-ext-java-1.2.49-m3.jar" -classpath "C:\classes;C:\lib*" com.xyz.otelc.MainClass
I have to dpeloy this on cloudfoundry and only thing i can do is cf push and no option to set class paths.

Related

WSO2 Carbon server - error when launching

I'm trying to run wso2 api manager from the source code. I downloaded carbon4kernel and the product-apim as stated on the site. The code builds successfully and imports into eclipse, but I can't launch the carbon server.
When I execute wso2server.sh I get the following:
Error: Could not find or load main class org.wso2.carbon.launcher.Main
Even if I add the class to the classpath, it finds the Main class, but I get:
SEVERE {org.wso2.carbon.launcher.Main} - org/osgi/framework/launch/FrameworkFactory
This is using the C5 server (although the download seems to suggest carbon4) and apiman 1.9.1.
Its worth noting that the binary distribution works straight out of the box, but uses an older version of carbon (AXIS2-based), but the source code version uses OSGi.
Does anyone have this working, or point me to where its going wrong please?
We don't have any products released on top of C5. So basically at the moment you cannot build API Manager with C5.
About building and running C5, which wso2server.sh did you try to run? I guess you tired with the one at distribution/kernel/carbon-home/bin/wso2server.sh. If that is the case it won't work. What you need to do is, build the project from the root pom.xml and at distribution/kernel/target the built zip file. Unzip it and try the wso2server.sh in the bin directory.
Alternatively, without building from source, you can download and try the C5 kernel binary from https://github.com/wso2/carbon-kernel/releases/tag/v5.0.0

Run junit tests contained in war archive from command line

I have a web application packaged in .war archive. It also contains unit test classes.
I want to deploy this application on different machines and each time run test from the command line. How can I do this taking into account that tests are in .war? I use Tomcat7. I do not consider usage of Ant.
Thank you!
You'll need a copy of the junit jar to run the test runner. Assuming it's already inside the WAR file it can be retrieved as follows:
unzip myapp.war WEB-INF/lib/junit-4.10.jar
Junit can then be run as follows:
java -cp WEB-INF/lib/junit-4.10.jar:myapp.war org.junit.runner.JUnitCore [test class name goes here]
Note:
If your tests need any other jars packaged inside the WAR they'll need to pulled out as well.

How to stop jetty runner from executing

Am using jettyrunner for executing my war files.I am using command java -jar jetty runner ex.war.But am running this jetty server from my java application by executing this commands from java.My problem is at first time its working good,but the second time if i am again executing another war file with the same code its executing the older war.i have found the reason that the older jetty server is keep on running.How could i stop this server from java in order to start the jetty server for another war.
One option should be:
http://wiki.eclipse.org/Jetty/Howto/Secure_Termination
Another would be to use the ShutdownHandler:
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java
Or don't use the jetty-runner directly like that from java code and just write a small embedded usage:
http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
Turned out, jetty-runner.jar doesn't have a feature to stop existing jetty process ran with stop-port and stop-key.
I found the answer in https://github.com/jetty-project/jetty-documentation/blob/master/src/docbkx/administration/runner/jetty-runner.xml
Then, to stop jetty from a different terminal, you need to
supply the same port and key information. For this you'll either
need a local installation of jetty, the jetty-maven-plugin jetty-ant plugin, or write a custom class
Fortunately, I was implementing gradle build, so jetty-ant satisfied my needs.

Jetty runner is not executing the war file

I have a project named as test using spring,hibernate and struts.It is running when am using eclipse.But when i export this project as war and execute it using jetty runner in command prompt it just extracted the project and listed the contents in the browser.But i want the project to be executed.I have tried with some other simple web application war using the same procedure and it works fine.But in my project its not working with jetty.
here is my code for jetty
D:\>java -jar jetty-runner-7.0.0.v20091005.jar test.war
i just listing some console output of jetty
INFO::RUNNER
NO tx manager found
deploying file:D:/test.war #/[webAppContext#86f241#86f241/,null,file:D:/test.war
can any one tell me a solution for my problem
1) use a newer version of runner, 7.6.3.v20120416
2) what context are you trying to navigate to, you might want to experiment with some of the other cli options on the runner to set the context and whatnot from the command line and experiment with that. This site has some good information on using this artifact as well.

Tapestry webapp with embedded Jetty

How can I configure a Tapestry5 project to run standalone (via java -jar) with embedded Jetty?
I'm looking for a short "recipe" regarding Tapestry5, Jetty, configuration of servlets/ handlers/ whatever is needed to connect the dots...
I've seen a few dots: How to Create an Executable War, Configuring Tapestry (ref Tapestry as servlet filter)
Edit: I'm thinking about a standalone running webapp due to server circumstances. It doesn't have to be embedded Jetty, but I can't rely on a stable appserver. Still looking for a recipe, though, so I don't spend much time on dead ends...
Also, I'd like for Jenkins (Hudson) to be able to stop and start the server automatically when deploying updates - I don't know if that influences what I can do with Jetty, f.ex.
Well, i believe this is a general "how to run a war question". Assuming you indeed have a war, you can use jetty or winstone to "run" it - see :
http://winstone.sourceforge.net
and
http://www.enavigo.com/2008/08/29/deploying-a-web-application-to-jetty/
In the first case, you can directly do
java -jar winstone.jar --warfile=<warfile>
https://github.com/ccordenier/tapestry5-hotel-booking/
<-- Check its maven build
http://tapestry.zones.apache.org:8180/tapestry5-hotel-booking/signin
I did some digging, and this is the short recipe I basically ended up following:
Start with the Maven Jetty plugin as configured in the pom.xml of the Tapestry 5 archetype
Add the stopKey and stopPort attribute to Maven Jetty plugin configuration
Let Jenkins CI run maven target jetty:stop and then clean install
Let Jenkins run shell script mvn jetty:run &
Voila - my Java app is up and running with automatically updated code, without any appserver.