Override NewRelic config file used by Cloud Foundry java build pack - java

I have a Spring Boot application deployed in Cloud Foundry, using the standard Java build pack. Since the app is bound to NewRelic, the build pack injects a NewRelic agent into the environment.
NewRelic documentation talks about adding a newrelic.yml file next to the agent jar location to customize instrumentation behavior. In the CF scenario, can it be located in the classpath of the deployed Spring Boot jar? How do I enable this behavior?

In the CF scenario, can it be located in the classpath of the deployed Spring Boot jar? How do I enable this behavior?
I don't know about that, but two things you can do:
Specify additional configuration options for the NewRelic agent through your bound user provided service.
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-new_relic_agent.md#user-provided-service-optional
(Optional) Any additional entries will be applied as a system property appended to -Dnewrelic.config. to allow full configuration of the agent.
If you were to fork the Java build pack, you could overlay your own configuration file.
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-new_relic_agent.md#additional-resources
Your custom file would go here: https://github.com/cloudfoundry/java-buildpack/blob/master/resources/new_relic_agent/newrelic.yml
You probably don't want to fork the build pack though as that creates a whole mess of other problems.
I guess a third option might be to use a .profile.d script, but that's a pain with Java apps because you have to put the files at the root of your JAR file. It could work though.
https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile
Hope that helps!

Related

Spring Boot : how to show actual classpath on startup or at runtime?

Is there a way to show Spring Boot actual classpath?
I am using STS to start my app and it reports that class XYZ is missing. Yet I checked my pom.xml and the dependency it self, and I can see the .class file.
I would like to show what is the real runtime classpath.
I used this (https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/), but I was looking for a solution that does not involve changing my app source code. A debug startup option type of thing. Actuator maybe. Whatever :)
Thanks
The classpath depends on the class loaders in use. For example Servlet Containers like Tomcat can load classes from multiple places e.g. shared lib directory or WAR archives. Spring Boot often repackages regular JAR to make it runnable by applying a custom layout. Without checking the class loaders there is really no way to tell what is part of the class path.
It's exactly what you said, debug option:
mvn spring-boot:run --debug

Is there a way to deploy a Maven project with "jar" packaging into Tomcat7?

My project generates a Jar as the output package and uses an external War file, available on our Artifactory, as the Web Application to be deployed on Tomcat (currently using version 7). This War file contains all libs and modules required for the application to run.
I have already packaged and ran those projects outside eclipse on a "vanilla" Tomcat installation. In this scenario, the Jar my project generates is loaded on the context.xml file this way:
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/igor/workspace/myapp/myapp-2.4.3.jar"/>
Is there a way I can deploy this project on Tomcat using Eclipse and still be able to debug it? Can I use the Jar generated for this purpose or do I have to deploy the workspace project?
As for the War file, do (or can) I have to add it as an dependency?
Thanks in advance!
EDIT
We actually provide an Web Framework, which is packaged as a war. Other applications that use that framework are exported as jars and loaded into the framework through the context file as cited above.
Your question is confusing probably because of your custom plugin/classloader and deployment which is sort of orthogonal to debugging.
What I recommend is you keep whatever system you have to build/package/deploy and use JVM remote debugging. That is do not use the Eclipse WTP since you seem to have custom steps for deployment but rather build your code deploy & run a separate Tomcat instance and then run the remote debugger in Eclipse.
You will get some hotcode swapping with this method but not as much as something like JRebel.. (which you could use also) it will certainly be better than constantly redeploying.

Deploy a war file in the application?

I am trying to integrate the monitoring tool JAMon into my current Spring application. Everything is fine except I don't know how to establish the monitoring information on UI or log file. What is more confusing, is from here
under the section "Setting up the JAMonAppender - Default Behaviour", I see this line:
Install JAMon.war in your application, so you can view your Log4J
statistics and log records.
is there anyway that I can install a war file in current application or there is something wrong with above description?
My understanding is the war file should deployed in an application server. Can I use it as a dependency?
My understanding is the war file should deployed in an application
server. Can I use it as a dependency?
Any WAR file must be deployed in an application container. It cannot be used as a dependency. For your sake, you missed point 1, where you can download the API with all its dependencies here.

How to filter webapp src/main/resources and see replaced values with JBossTools

I have a maven web application which has the file src/main/resources/appContext-ejb.xml file which has the ${version} placeholder in it.
I want that placeholder to be replaced by the version of the maven project, so I 've configured the maven resources plugin to enable filtering of the file.
After compiling with eclipse I can see the file under the target/classes directory with the correct (replaced value).
Also when packaging the war archive the file is being replaced without problems.
My problem is that I want to use the JBoss Tools eclipse plugin to start my web application, so I create a jboss server, and add my web application to it. When I start jboss (from within eclipse using jboss tools) and try to use my application the piece of code which needs that file with the replaced value fails telling that ${version} was not replaced.
Does JBoss Tools plugin use src/main/resources instead of the contents of target/classes?
How could I configure or make Jboss Tools use the already replaced file in target/classes?
I 've searched the web for this and I 've found a lot of information on how to enable filtering to web resources so that jboss tools takes changes on the fly, but I believe that that's not helpful for me because this file should not be used as a web resource because it shouldn't be served as web content.

Deploying to Glassfish via Eclipse

I have set up a project inside Eclipse which I can debug on a Glassfish (3.1) server using the Eclipse Glassfish plugin. So when I click 'Debug on server', it uploads fine and I am able to step through the code correctly etc.
The problem is that I don't know if the program is being compiled/build (to a new .war) each time I press debug. I have got an Ant script in the project (as I previously built the project via terminal) but I'm not sure if it is actually being used in Eclipse.
Is there any way to check if my ant script is being run?
Also, how does Glassfish know what resources to upload? Does it just look for any .war files in the project?
Not sure about this particular jar plugin but as far as I know here is how Eclipse handles web applications:
Eclipse automatically compiles all of the sources in the class path
Then it creates a configuration file which tells Application Server to look for webapp on your project folder and does some mapping based
on your project setup. This will not create a WAR file. Eclipse will
just map WEB-INF/classes to {projectDir}/bin, your classpath jars to
WEB-INF/lib and so on.
When launching the Application Server, eclipse will feed it the config file made above.
Actually answering your question: Eclipse will not use the Ant script you created, nor will it create a WAR of any kind. It will just use project configuration to properly map project folders to web application structure.
Again, this is how eclipse handles things by default, the plugin you're using might do something different. This is based on my experience and is not based on some kind of documentation.

Categories

Resources