JRE 1.6 in Maven repository (public or private) - maven

is there JRE 1.6 available in some public Maven repository we could proxy in our Nexus?
if not, can somebody please provide a hint on how to deploy JRE to a Maven repository?

here's the solution I found:
Zip the JREs (jre-linux32-1.6.0.23.zip and jre-jre-win32-1.6.0.zip in
my case).
Upload them to your Nexus repository through web UI (or deploy manually with "mvn"), set the artifact parameters: groupid="oracle" artifactid="jre-win32" / "jre-linux32", set the
right version and packaging type "zip".
modify your pom.xml to download and unzip the dependency during the build (I bound it to "prepare-package" phase).
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>oracle</groupId>
<artifactId>jre-win32</artifactId>
<version>1.6.0.23</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<!--<destFileName>optional-new-name.jar</destFileName>-->
</artifactItem>
<artifactItem>
<groupId>oracle</groupId>
<artifactId>jre-linux32</artifactId>
<version>1.6.0.23</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<!--<destFileName>optional-new-name.jar</destFileName>-->
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
that's it. The JRE will be downloaded and extracted to
target\alternateLocation folder.
you can use "copy" goal instead of "unpack" if you want to only copy the ZIP files without extracting them.

Your requirement is somewhat valid use-case. But IMHO, putting it in to a maven-repo is not the way to do it.
Other applications, achieve this requirement by getting the executables directly from the provider. For an example build servers like Hudson/Jenkins need to download Java/Maven upon users selection and AFAIR Jenkins download them directly from the Oracle site. (Since oracle asks you to login before download they use SSO mechanism).
A similar solution along those path would be suitable for you.
Even if you host your JRE in m2-repo there are certain security problems. JRE is a sensitive program. Even if you say that you have hosted the same JRE from oracle, I would rather download it from oracle.

Here you can read how to install a jar into a maven repo. But why do you want to install the JRE jars in a maven repo?

Related

How do I include third party libraries in openLiberty maven build

I'm currently running a PoC with open Liberty and I'm having a bit of trouble with libraries.
The short of it is our project has a few third party jars that need to be included as libraries, but I can't figure out how to include them when I run mvn install in my Open Liberty project.
I'm trying to configure them in server.xml as follows:
<library id="MyLib" name="My Libraries">
<fileset dir="${server.config.dir}/myLib/" includes="*.jar" id="myLib"/>
</library>
I had hoped they would be picked up by the maven build, but obviously not.
What steps do I need to take to make make sure my library jars are placed in the correct place when running mvn install?
First of all, I will recommend the easiest approach which is packaging the libraries inside of your application (no server.xml <library> config needed this way). If you are using the maven-war-plugin, then any non-provided dependencies will automatically end up in WEB-INF/lib/ of your application. However, if you have more than 1 application in your Liberty server that need the same libraries, this may not be a good solution.
On to your original question, you can use the maven-dependency-plugin to copy any maven artifact into a particular location during the build. When using this plugin to set up a <library>, be sure to bind the copy step to the prepare-package phase.
Here is an example of adding JUnit to ${server.config.dir}/myLib/ during a Maven build:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/myServer/myLib</outputDirectory>
<destFileName>junit.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>

Export OSGi bundles to a specific folder using maven

Can anyone plz guide me how can I copy the generated OSGi bundle to a different location on the disk?
I am using maven for building the OSGi bundle.
Complete Solution: Update on 9th Jan, 2014:
I got a better approach and updated the pom.xml with following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-installed</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<outputDirectory>some-other-place</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This was able to copy once the bundle generation was done an I could give the destination folder too.
When do you want to copy your bundle?
Assuming you have a project generating the bundle, then it should be available in your target folder, and will also be installed (running mvn install) in your local repository (~/.m2/repository/...).
You could just use a cp command to copy it wherever you want.
Deploying it to a test folder as part of the build is not necessarily a great idea: you're making your build dependent on machine specific settings or magic injected properties. That said, if you wanted to do that anyway, I'll use the following approach:
have a separate maven project which depends on the bundle and just deploys it wherever you like
define a property specifying the target directory (you can pass it on the command line, define it in your settings.xml or provide a default value for in your pom.xml)
use the maven-dependency-plugin:copy-dependency goal in your deployment project to copy your bundle
Guess this question is not really related to OSGi, more to maven... maybe you could have a look at the maven resources plugin, specifically http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html which helps you copying arbitrary resources.

Let MVN store libraries in MyProject/lib/?

I would like maven to store the dependent jars in the project specific lib folder instead of in the default MyUser/.m2/repository/. Not everybody has internet access when he gets the project, and copying the global local repository seems like a less-than-ideal solution.
How do I persuade maven to store and use these dependencies in a local, relative, project specific folder?
Seems my question is a rephrased version of this Stackoverflow question
I did something like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${mvn-dependency-plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/${local-lib-dir}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<build>
The only downside is, that eclipses maven still refer to the jars in the local repository.
I'm sorry to say that, but if you really like to have a lib folder which contains the dependencies you are working with you are back in Ant times and start also checking in the lib folder into your version control which is really bad.
If you argument that an internet access does not exist you should start using a repository manager like Artifactory, Nexus or Archiva which is installed within the local network and only the repository manager needs the internet connection. Everyone else just uses a version control tool to checkout the sources and can start working with the project.
You can manage your external dependencies like this:
<dependency>
<groupId>mydependencygroup</groupId>
<artifactId>my.artifact</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\myartifact.jar</systemPath>
</dependency>
The lib folder is inside your src folder.
Hope it hepls.

Unpack an EAR file using maven

I have an EAR file from some build. I want to extract the contents of this EAR file into another folder. I am confused how to do this. I have looked and tried
http://maven.apache.org/plugins/maven-ear-plugin/
and
http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
but either maven is unable to find the file or it has dependency issues.
Since I am new to maven I don not understand how to set these plugins up.
I got the following error on using the below plugin.
Failure to find ECM:ECM:ear:1.0 in http://repo.maven.apache.org/maven2 was cached in the local repository
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>ECM</groupId>
<artifactId>ECM</artifactId>
<version>1.0</version>
<type>ear</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/earoutput</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
You can do it using dependency:unpack-dependencies. I just modify my answer because according to your comments, your ear is generated by some other build. If you do not have an Enterprise repository that you can deploy your ear artifact, you have to use "system" scope, but please note that it is usually discouraged.
Add below dependency to your pom.xml
<dependency>
<groupId>ECM</groupId>
<artifactId>ECM</artifactId>
<version>1.0</version>
<type>ear</type>
<scope>system</scope>
<systemPath>/path/to/your/abc.ear</systemPath>
</dependency>
Add the below plugin to your postBuild module pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>ECM</includeArtifactIds>
<outputDirectory>${project.build.directory}/earoutput</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Have you looked at this example of Maven EAR plugin for Unpacking a module yet?
The Maven Dependency Plugin and its unpack goal can do this.
Sample configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>myear</groupId>
<artifactId>myear</artifactId>
<version>1.0</version>
<type>ear</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/earoutput</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This takes the 'myear.ear' artifact and extracts it to the 'target/earoutput' directory. This also works with JARs, WARs and any other zip-like file. The phase this executes under is 'package' - this may be too late if you need to use these resources in other parts of the build. Change the phase to something earlier such as 'generate-resources' if needed.
You mentioned that you already tried using the dependency plugin. Is the EAR file from another Maven project, and has it been installed in the local Maven repository? If it still doesn't work post the plugin configuration you tried to use.
(edit: update information on dependencies and local repository)
For this to work, your EAR file needs to be put into your local Maven repository (this is just a directory on your disk). But if other people need to build your project as well, you have a few options:
import the EAR into your local repository, and also deploy to a remote repository so everyone can get it (recommended, but requires you to set up a corporate Maven repository)
give the EAR to everyone and have them put it into their local repository using a couple of Maven commands (might be OK for a few developers, less overhead than setting up a whole repository server)
check the dependent EAR into source control under your project and unpack it (not the recommended way of doing things) in a goal in your project
Importing into your local repository is easy. It's very similar to these instructions.
Use the following command:
mvn install:install-file -Dfile=<path-to-EAR-file-on-local-filesystem> -DgroupId=myear
-DartifactId=myear -Dversion=1.0 -Dpackaging=ear
(modify path, groupId, artifactId and version as needed)
Group ID and artifact ID are there simply to uniquely identify artifacts.
Once you install this in the local repository, the dependency plugin should work and find the artifact.

maven-install-plugin: Can i define a custom packaging type but get the artifact installed as jar in the repo?

I am trying to come out with a plugin to detect and process Java EE application clients.
I created a new packaging type called 'car' through META-INF/plexus/components.xml (http://maven-car-plugin.googlecode.com/svn/trunk/maven-car-plugin/src/main/resources/META-INF/plexus/components.xml) and a corresponding mojo for Java EE app clients. I have pretty much followed the same steps as the maven-ejb-plugin.
The behaviour i want is the same as the maven-ejb-plugin: Defines an ejb packaging type but the artifact gets installed in the repo as a .jar and gets bundled in the ear as .jar too.
I believe must be configurable some how because ejb packaging type gets installed as .jar but war packaging type produces a .war.
The problem in my case is that a .car file gets installed in the repo and a .car file gets bundled in the ear.
Does anyone know how to make sure it gets installed in the repo as a .jar file?
I ran into the same issue you have, except, I'm building a .war file and wanted a .jar file installed into my local repo. What I did was use the maven-jar-plugin to create a jar file in addition to a war file, it's generated in my /target directory. I also used the maven-install-plugin to install the outputted jar to my local repo.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-jar</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.artifactId}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Perhaps you could try using the packaging parameter in maven install plugin to see if that helps in your case?
I would assume you would have to specify
<packaging>jar</packaging>
as well in the component descriptor. Otherwise it looks correct to me..

Resources