Creating stub files for ejb in maven build tool - maven

Team,
Our project makes use of EJB, was 6.1 is our server, While deploying the code , am in need of stub files to be present in EAR (Maven Generated). Inorder to achieve this, am using was6 plug in our pom.xml
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>was6-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>ejbdeploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
For this we need to set the environment variables "WAS_HOME".
But we cannot set the wasHome in continuum build server and hence we are getting BUILD ERROR - "wasHome not defined"
Is that any other way to achieve this?
- Creating the stub files for all ejb class without using WAS 6 maven plugin in Maven.

WAS6_HOME environment variable is the default value used by was6-maven-plugin to know where Websphere is located,
but people often use the wasHome attribute to indicate this.
From here it's possible to use Maven properties in the pom or in the settings file and Maven profiles.
On the other hand, you can generate the EJB Stubs without the maven plugin, but you will always need to know where websphere is installed.
Regards

Inorder to achieve this we can set the parameter(ejbdeploy = true) in was6 server install configuration xml
and its worked.
Thanks for all the responses.

Related

What's the proper way to generate a manifest with DS and maven-bundle-plugin?

I am using today maven-bundle-plugin to generate the manifest of my projects. Due to others constraints, my modules use the "jar" packaging (i can't use the "bundle" packaging), and currently, my pom look like this :
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
...
</instructions>
</configuration>
</execution>
</executions>
</plugin>
I'd like now to generate a 'Service-Component' header and the DS xml descriptor from my annotated components, but adding "<_dsannotations>*</_dsannotations>" is not working :
Service-Component header is correctly generated, but the xml are not present in the jar
If i rebuild my maven project without a clean goal, then the 'Service-Component' header have duplicates references : After digging in the code, the plugin use the old generated manifest from target/classes/META-INF/MANIFEST.MF and merge it with the new generated one. The 'Service-Component' is then concatened
So, how should i configure my pom for this to work ? For now, i use the 'unpackBundle' option (in order to have the xml in my bundle) and an empty src/main/resource/MANIFEST.MF (in order to bypass the merge of the old manifest) : it looks ugly :-)
Moreover, the 'bnd-maven-plugin' work as intended, but the integration with maven are maybe too light (or not documented?), as 'global configuration' in a parent pom, generation of the Bundle-SymbolicName or Bundle-Name, etc.
Thanks!
There is a newer plugin for maven that is closer to both bnd and maven. This plugin does not take over the jar target and properly follows the maven phases.
Take a look at http://njbartlett.name/2015/03/27/announcing-bnd-maven-plugin.html

How add local dependecy in assembly JAR

I have a multimodule Maven project with several dependencies. I want to build a fat executable JAR containing them as well as my own compiled classes. I found maven-assembly-plugin to be just what I needed except one nasty problem.
Some of my dependencies are local and distributed with project sources. I use system scope for them. It looks something like this:
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/forms_rt.jar</systemPath>
</dependency>
The problem is that for some reason these libraries aren't unpacked and bundled with the rest of dependencies in result JAR.
I know that usage of system scope is considered bad practice, and in fact I even can find some of them (though quite outdated) in Maven repositories, but anyway it puzzles me how it can be solved with maven-assembly-plugin.
Just in case my plugin configuration looks like this:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>repoll.server.Repoll</mainClass>
</manifest>
</archive>
<finalName>${project.build.finalName}-full</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
As I understood I have to write custom descriptor, which e.g. includes and unpacks all JARs from ${project.basedir}/lib directory, but after several unsuccessful attempts I still don't know how to do so.
I've managed to find solution here. It's described in this question.
In short, the whole problem was in usage of system scope. It turned out, that such dependencies are filtered out by default, which I found out by running mvn package with debug output enabled (-X/--debug).
When local repository is defined for these JARs, distributed with project, they are unpacked by maven-assembly-plugin as exepected.

Unable to disable generation of empty JAR (maven-jar-plugin)

Sometimes, my Talend Open Studio components have resources but not Java sources (they are purely metadata components). I need to disable the generation of JAR files in such a case.
I configured the maven-jar-plugin this way:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<forceCreation>false</forceCreation>
<skipIfEmpty>true</skipIfEmpty>
<useDefaultManifestFile>false</useDefaultManifestFile>
</configuration>
</plugin>
but I still get the ${project.name}.jar file with pom.properties, pom.cml, the manifest and an empty file App.class containing only "class {}"
While I can disable the includes of all maven stuff using this:
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
I still get a JAR with the manifest file inside it
Are there some configuration parameters I misconfigured?
Most efficient way to disable the creation of jars is to configure the maven-jar-plugin like this:
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
It will place the default jar creation in the none phase, it will never be run.
I found the solution by myself, even if it's only a workaround. I delete the JAR using a delete antrun task if /src/main/java directory doesn't exist:
<!-- remove the empty JAR if not needed -->
<if>
<not><available file="${basedir}/src/main/java" type="dir" /></not>
<then>
<delete file="${project.build.directory}/${project.name}-${project.version}.jar"/>
</then>
</if>
this task requires antcontrib to work properly and, ofc, it doesn't work if you plan to do releases with maven (but it's ok for metadata-only components, like Talend Open Studio plugins)
You can instruct maven-jar-plugin to not generate META-INF/maven/*/pom. files, as explained in Maven Archiver Reference.
Also, you can use its skipIfEmpty option.
Following code combines both these (just to have them copy-paste ready):
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
...
This works fine, but when you do mvn install, it fails due to missing project artifact.
Similar problem will probably be with mvn deploy and with release, but I didn't check these.
However, if you can live with antrun's delete, the property skipIfEmpty will probably work well for you, and is a bit more elegant. At least it does not introduce a new execution and its dependencies etc.

Client JAR containing maven dependencies

I'm building a service which contains a client module which is using Spring. The service which will be implementing the client does not contain spring but it has a dependency on the client which has dependencies on Spring. Ideally I would like the client to include the needed Spring dependencies in the JAR but I can't seem to figure out how to accomplish this. I've seen a few different examples of using maven-assembly-plugin but I would prefer to not have to use something other than "mvn clean package" to accomplish this.
Any help is appreciated.
The maven-shade-plugin allows you to build an uber-jar containing some (or all) of your dependencies. It should allow you to do what you need.
By binding the assembly plugin's single goal to the project's build lifecycle, you can accomplish what you want by running mvn clean package.
Cut/pasting the pom configuration to do this from the usage page of the plugin,
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</project>
Of course, you would tweak either either to use a different predefined descriptor or even use a separate descriptor file.

Maven executable jar with libraries on external path

My jar is not running, I can tell it tries to run as the log4j file manage to create the log folder but then nothing happens and the log is in blank.
My problem is I have the jar file in a folder called bin and the libraries in a folder called lib
I'm triying this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${staging.dir}/bin</outputDirectory>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>com.Main</mainClass>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
and
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${staging.dir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I also tried with maven-assembly-plugin, but it packs everything on the jar and I really need to have the folders bin and lib
What do I need to setup to make it work correctly?
EDIT: META-INF file
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: me
Build-Jdk: 1.6.0_26
Main-Class: com.Main
Class-Path: ../lib/ojdbc6-11.2.0.jar ../lib/sqljdbc4-4.2.0.jar ../lib/
mysql-connector-java-5.1.17.jar ../lib/hibernate-core-3.6.5.Final.jar
../lib/antlr-2.7.6.jar ../lib/commons-collections-3.1.jar ../lib/dom
4j-1.6.1.jar ../lib/hibernate-commons-annotations-3.2.0.Final.jar ../
lib/hibernate-jpa-2.0-api-1.0.0.Final.jar ../lib/jta-1.1.jar ../lib/s
lf4j-api-1.6.1.jar ../lib/hibernate-entitymanager-3.6.5.Final.jar ../
lib/cglib-2.2.jar ../lib/asm-3.1.jar ../lib/javassist-3.12.0.GA.jar .
./lib/slf4j-log4j12-1.6.1.jar ../lib/log4j-1.2.16.jar ../lib/commons-
codec-1.5.jar ../lib/lablib-checkboxtree-3.3-20110114.141734-3.jar
SOLUTION
turns out the META-INF file is incorrect. The reason is that maven-archiver-plugin renames SNAPSHOT libraries with a timestamp as default behaviour
to override that use this, as instructed by the Maven Archiver doc:
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>com.Main</mainClass>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
other than that, I hope people find useful the maven code at the start because it does work, just beware the SNAPSHOTS in your projects
The above all seems OK. Here are some things/questions you may want to try/confirm/answer:
Are you running this from command line? I.e. using java -jar <your.jar> or are you starting it e.g. by double-clicking the file, etc.? If not, try running it from the command line to see what happens
Try using mvn exec:java to see if that starts your app (maven-)regularly. See http://mojo.codehaus.org/exec-maven-plugin/usage.html if you are not familiar with exec plugin
Can you use regular Java System.out.println instead of logging to confirm that it actually starts? Having a zero-size log might be a logging configuration issue
I see you have some DB libraries above. Can you put some println (or better logging, but only after you confirm your logging actually works) statements around basic initialization, to confirm that you are not just stalling there (provided that's what's happening - you don't mention any exceptions or other issues in specific)
A lot depends on the actual application code, but hope some of the above might help you pinpoint the issue.
As a side note, is your main class really com.Main? If yes, may I suggest to change that to something more appropriate - e.g. com.yourdomain.yourapp.Main or something along these lines. Not that this will change the above result, just a stylistic comment.

Resources