Viewing version source for multi release JAR (MRJAR) - maven

I'm trying to attach the Java 9 or Java 11 source for some projects released as MRJARs, namely jersey-container-jetty-http-3.0.2 and junit-platform-commons-1.4.0.
Looking at the jersey-container-jetty-http-3.0.2-sources.jar file in my ~/.m2/repository there is no META-INF/versions directory and the .java files in standard package locations are for Java 8 (pre module system). This is also the case if I unpack https://repo1.maven.org/maven2/org/glassfish/jersey/containers/jersey-container-jetty-http/3.0.2/jersey-container-jetty-http-3.0.2-sources.jar
This is a big bummer for my debugger :(
I was able to download the full source code from https://github.com/eclipse-ee4j/jersey/releases/tag/3.0.2, and it contains the following directories, with source:
containers/jetty-http/src/main/java11
containers/jetty-http/src/main/java8
I thought maybe this was just a Jersey problem, but looking at junit-platform-commons-1.4.0 I see a similar issue. Neither my ~/.m2/repository nor https://repo1.maven.org/maven2/org/junit/platform/junit-platform-commons/1.4.0/junit-platform-commons-1.4.0-sources.jar contain code for any java 9+ version but the release JAR contains /META-INF/versions/9/org/junit/platform/commons/util/ModuleUtils.class.
So my question: Is including source for multiple Java versions supported by Maven? If so, where are the Java 9+ source files be located?

The maven-source-plugin:jar goal which:
[...] bundles all the sources into a jar archive.
doesn't mention MRJAR explicitely but it has the parameter:
Name
Description
<includes>
List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.

Related

Kafka Connector - Packacking jars

QUESTION
I am not a maven pro and I got stuck trying to package a Kafka Connector. There are two options for packaging it:
Either you produce a folder with a jar that contains the connector + all the dependency jars - all the kafka-specific jars
Or build a fat jar with all of the dependencies (and I also assume without the kafka-specific jars again, but it is not explicit in the docs).
I am following docs on confluent webpage and the connector I am trying to package is this one on github.
What I tried, after cloning the repo with git, is the following mvn clean package. But this seems to create only a single jar of the original project with the dependencies in mvn cache (~/.m2/repository/).
Google also has link on how to create a fat jar, but I would need somehow to specify which jars I want to exclude from the fat jar.
Thanks
UPDATE
Now I am running:
connect-standalone /etc/kafka/connect-standalone.properties /etc/kafka/connect-cdc-mssql-source.properties
Where /etc/kafka/connect-standalone.properties contains the following line:
plugin.path=/shared_win_files
And ls -al /shared_win_files contains the following:
kafka-connect-cdc-mssql-0.0.1-SNAPSHOT.jar
And jar tvf kafka-connect-cdc-mssql-0.0.1-SNAPSHOT.jar contains the following:
6996 Thu Sep 07 14:47:24 BST 2017 com/github/jcustenborder/kafka/connect/cdc/mssql/MsSqlSourceConnector.class
where MsSqlSourceConnector.classis basically this class here which implements the Connector.
But when I try to run the connector with the command above, I get an error
Failed to find any class that implements Connector and which name matches com.github.jcustenborder.kafka.connect.cdc.mssql.MsSqlSourceConnector
It gives a massive list with all available plugins, but mine is not in there.
Currently, an easy way to package your connector with maven is to use maven-assembly-plugin. This basically entails two main steps:
Define one or more assembly descriptors and save them under src/assembly.
Doc: http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
Example: https://github.com/confluentinc/kafka-connect-elasticsearch/blob/master/src/assembly/package.xml
In the descriptor, among other things, you may choose the packaging format of your archive, files and directories to include or exclude, as well as specific settings regarding your projects dependencies.
Include the plugin in your project's pom.xml
Example: https://github.com/confluentinc/kafka-connect-elasticsearch/blob/master/pom.xml
This mainly requires you to define the configuration and execution sections of the maven-assembly-plugin section. Additionally you can associate calls to specific assembly plugin descriptors with certain maven profiles that you may define.
Finally, stay tuned because packaging your Kafka Connect plugins (connectors, transforms, converters) might be significantly simplified soon.
Following Konstantine's answer how to package jars.
The remaining problem was that when specifying plugin.path=/abc in KafkaConnect config, you have to be careful.
You can either put a fat jar like this:
/abc/fatjar.jar
Or you have to create another folder in abc and put all the related jars into that folder like this:
/abc/my-connector-a/connector.jar
/abc/my-connector-a/connector-dependency.jar
...
As in my case, it was treating jars as separate plugins.

How Do You Specify Where The Gradle Wrapper Installs Gradle?

I have an off the shelf application that ships a version of gradle with it. It also has scripts that are hard coded to set GRADLE_HOME to this location.
I want to zip up this dir, put it in nexus and replace it with the gradle wrapper.
How do I configure the gradle wrapper to download this zip from nexus and extract it to a specific location in the project?
EDIT: In the gradle-wrapper.properties I have
distributionPath=wrapper/gradle
However, I end up with it being unzipped to
...\wrapper\gradle\gradle-2.3-bin\8gn7esgljqyucijpbynjk93oc\gradle-2.3
How do I get it to unzip to the path I specified and not to the subdirs?
The location to which Gradle gets unpacked is a combination of the distributionBase and distributionPath properties in gradle-wrapper.properties file. The location specified by distributionPath will always be considered as relative to distributionBase. The only available values for distributionPath are GRADLE_USER_HOME and PROJECT. Even when using PROJECT the wrapper will still generate the folder structure you see above.
If you want to control this more precisely I'd suggest not relying on the wrapper to do this and instead add a task to your build specifically for this purpose.

What is an exploded EAR?

Can someone please explain what's an exploded EAR ? I checked in google but couldn't find a clear answer.
Is it a different format?
What's the difference to a non exploded EAR?
A compressed EAR file, with extension .ear is just a ZIP file containing the directory structure of a JEE project. It is normally used in order to deploy a JEE project.
An exploded EAR file is just the uncompressed content of the above.
Incidentally speaking, war and jar files are also compressed in ZIP format.
The use of the wording "Exploding" instead of "decompressing" a ZIP file seems to be traditional in the java community, and is present in official documentation.
E.g.: www.java2s.com/Code/Java/File-Input-Output/classforexplodingjarzipfilesontothefilesystem.htm (on a IBM contributed source file belonging to Eclipse ).
They can be exploded with the jar command.
You can also use any compression utility, provided you keep the directory structure intact.
e.g.:
jar xvd /myapp_path/myapp.ear

bndtools Activator bundle

How can I create a simple bundle with an Activator in bndtools?
It keeps saying that:
The JAR is empty: The instructions for the JAR named com.myproj did not cause any content to be included, this is likely wrong bnd.bnd /com.myproj Unknown Bndtools Problem Marker
Unused Private-Package instructions, no such package(s) on the class path: [com.myproj] bnd.bnd /com.myproj Unknown Bndtools Problem Marker
The way I create this project in Eclipse is:
Create new "Bndtools OSGi project"
Right click, configure - Convert to Maven project
Create Activator.java in package com.myproj.
Add com.myproj to private packages
Set activator to com.Activator
Here is my bnd file:
Bundle-Activator: com.myproj.Activator
Private-Package: com.myproj
My generated jar is empty. Any tips?
P.S.: Here is my eclipse project (exported as a zip-archive) in case it sheds any light on things: https://dl.dropbox.com/u/9162958/scraper.zip
My guess is that "Convert to Maven project" is the trouble. This likely has changed the Eclipse classpath for the project from the bnd default bin folder to 'target/classes'. Can you confirm that it works without converting to maven?
bnd can work with other places for the bin folder, you must set the ${bin} property (preferably in cnf/build.bnd). There are some writeups how to use bndtools with maven. The reason that bnd does not follow Eclipse's settings here is that they are not available without Eclipse and a design goal of bnd is that it builds anywhere: the bnd file must therefore be the final arbiter of information.
Anyway one more tip ... activators are not the right way to build OSGi builds since they are an evil singleton. Declarative services is far superior and we should actually have used a similar mechanism when we designed OSGi.
My setup:
Eclipse Luna 4.4.0 (20140612-0600)
Bndtools 2.3.0.REL-20140510-023245
Here is how I made it work:
I downloaded you exported scraper.zip.
Created and empty workspace in Eclipse.
Imported your project from the ZIP archive into the empty workspace.
The default cnf project was automatically created.
By default, bnd is configured to use the bin directory for compiled *.class files while your Eclipse project is configured to use target/classes. Therefore, I had to change this settings in cnf/build.bnd by adding a single line:
########################
## BND BUILD SETTINGS ##
########################
bin: target/classes
Now, after cleaning and rebuilding the project, bnd creates generated/scraper.jar that contains your Activator.class.
Notes:
You could also adapt your project configuration to use the bin directory instead of target/classes but I assume that you will use Maven later on.
When using bndtools, it sometimes helps when you start with an empty workspace and import your projects one-by-one.
There is a bug in bndtools 2.4 which causes some problems if there are multiple source directories per project. Therefore, I'm still using version 2.3

How to add OSGi WAR bundle ine eclipse target platform

For my OSGi development i have setup a target definition (.target file) which references two directories. Eclipse picks up all the jar files inside these directories and adds them to the target platform. But one of the bundles i have is a WAR file (.war extension) which is run using pax-web. Eclipse doesn't show this in the list of bundles available. Is there any way to add a particular bundle directly into the target definition? Any way out that i might be missing?
One workaround i found was to rename the .war file to .jar. Pax-web doesn't care about the extension, eclipse picks it up and so everything runs fine. But i am not very convinced if this is the right solution.
Thanks.
Bug 355890 was fixed for 3.8/4.2. You can now include archive files that are not jars (i.e. WAR files).
There is a known bug filed on eclipse on this very issue. Until it is fixed, the only workaround is to rename the file to have the .jar extension.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=355890

Resources