Maven example to add extended agent - maven

I m writing my own extension with maven and I wanted to embed the extension and create a single jar. I saw an example in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/examples/extension/README.md#embed-extensions-in-the-opentelemetry-agent but this is in gradle. Does any one have an example for maven?
I tried with maven-shade-plugin, but I m not sure how to output opentelemetry-javaagent jar with the extension jar embedded inside

Related

How to include only specific files from the main/java to be part of jar to be published to using gradle?

I don't want the whole main/java to be pushed as Jar
Instead, I want only specific folders inside main/java to be part of the jar.
How do I achieve it?
Actually, this part of your build.gradle has nothing to do with creating the JAR file. It just defines a publication that refers to the Java component built by your Java project. One part of this Java project is the task jar, which actually creates the JAR file. This task is of type Jar, so it offers methods to either exclude files following a pattern or to only include files following a pattern:
jar {
include '**/path/to/included/files/*.class'
// alternatively
exclude '**/path/to/excluded/files/*.class'
}

Include the bytecode of a JAR file in a gradle library vs. just adding it as a dependency

If I add a JAR file to a gradle project's depenencies, the code compiles just fine, but after publishing to maven (publishToMavenLocal), the classes from the JAR are not found.
Obviously, this is because the jar is added as a "dependency" and not part of the project itself. Is there a way to get the contents of the JAR file to merge into the library? Do I need to make a separate maven repo for each JAR?
You can always try to create a fat jar which includes dependencies. You can follow the instructions provided here https://www.baeldung.com/gradle-fat-jar

Repackaging a dependency as a fat jar

I have two maven projects. One is a library and the other one is an example utilizing this library.
Because my customer is a little old-school he would like to run the example without using maven and requires that the example contains a folder "lib" containing a fat jar file with the lib.
Using maven-assembly-plugin I have been successful in repackaging my lib. as a fat jar but only if it is declared within the lib.'s pom file. But from my POV I would like to have this declaration in the pom file of the example and not the lib. (in order to avoid polluting my lib. with this nonsense).
So my question is: Is it possible to build a fat jar file for a dependency in a maven project? That is, can I use a plugin like maven-assembly-plugin to repackage my lib. as a fat jar from the pom of my example project?

Maven: generate MANIFEST in custom location

I am trying to retrieve the implementation title and version for a maven jar module. If I use Myclass.class.getPackage().getImplementationVersion() on the built jar, it works, but the same does not work in a debugging environment where the jar is not built, but classes are available.
I am aware of using the Maven JAR plugin to generate the MANIFEST for a maven jar module. So one approach I am considering is to somehow create a copy of the MANIFEST in the generated sources output folder, which I include in my debug classpath. To achieve this:
Is it possible to generate the MANIFEST file in a custom location? If so, what is the plugin and execution configuration necessary?
If not, in which location is the file generated, so I may copy it my custom location using the maven-resources-plugin?
The Manifest file is created dynamically when the archive is assembled. There is no default way to do this.
The easiest I would come up with is to put a MANIFEST.MF in a resource directory, let Maven filter it and add the directory with a profile. This would mimic the way Maven Archiver creates your MANIFEST.MF. The hard way would be to create a custom plugin around Maven Archiver and pass the very same config as to the JAR plugin and enable it with a profile again.

include source files in war maven

I want to include source files also in Maven - War file . Some plugins in maven will do that but they are including source files in classes folder. But my requirement is that when I import the same war file again into eclipse I should be able to work on that war like any other normal war.
Basically I should be able to work on the same war after importing it to eclipse when I build maven project. (I'm using maven3. )
I remember that's not trivial because the war-plugin doesn't support the handy includes-configuration-element you know from the jar-plugin by default.
Therefore I suggest you to use the maven-assembly-plugin to configure the inclusion of your sourcefiles. You only need to define an assembly descriptor, where you list includes and excludes of your war-package. Maybe you can reuse one of the predefinied assembly descriptors to save some time.

Resources