Creating a ZIP file of an EAR with Maven - java

I'm got a pretty simple question... I have a Maven 3 project set up like so:
Root POM project
- EAR project: depends on the WAR project
- WAR project
I'd like to use the assembly plug-in to make a ZIP file containing the exploded EAR (which contains the WAR). Any suggestions on how I should do this? Should I put the assembly configuration details in the root .pom or EAR .pom?
Thanks!
-Jon

You could have a third project, say earzip, with a dependency on the ear project. This project can have the necessary configuration (assembly descriptor and other plugin definitions as required) to explode the ear and zip it up again as suitable. This will keep your parent pom clean, as well as not put multiple things in your ear pom.

When I was looking for the way to run batch script from ant (~1 year ago) I found only the following solution:
In the pom that builds your parent project add runant plugin
In the ant script (1) add target that runs a batch script (if on Windows)
In the batch script (2) add archiving task.
No point to add zipping task to the pom that builds an EAR (IMHO). It should be parent pom task.
I hope that these threee would do the magic.
Good luck!

Related

Configure maven to package fat jar without unpacking dependencies in a vertx project, like spring boot does

How can I tell maven to include dependency jar files while building a fat jar, rather than unpacking them to .class files?
I have a vertx 3.6.0 project producing a fat jar. I am using vertx-maven-plugin:1.0.13, and I run mvn clean package to build. In order to take advantage of Veracode SCM (static scanning), the dependencies inside my fat jar have to be intact, meaning the original dependency jar files have to be contained inside my fat jar. Maven is unpacking all dependencies though, so all I have are class files.
We have another spring boot project which works as expected. It seems the final spring boot repackage goal puts all the dependency jar files in the BOOT-INF dir inside the jar file.
Final 2 goals using vertx-maven-plugin:
maven-jar-plugin:2.4:jar
vertx-maven-plugin:1.0.13:package
Final 2 goals using spring-boot-maven-plugin:
maven-jar-plugin:2.4:jar
spring-boot-maven-plugin:2.1.2.RELEASE:repackage
I've searched the docs for vertx-maven-plugin and all over https://maven.apache.org and elsewhere without any luck so far.
Is there a way to get this same repackage behavior for a non spring boot app?
You can't do that with Vert.x because it doesn't do fancy classloading.
But since it's embeddable, you can create a SpringBoot app that just starts Vert.x. Then you'll get your dependency scanner working.
But I would first check with Veracode if it' can't inspect your POM or Gradle build file instead of scanning a JAR.
If your packaging requirement is for the veracode scan piece, you would probably try packaging your project artifacts into a tar, or zip using the maven-assembly plugin.
Veracode couldn't scan a dependency jar inside another jar for a non-spring boot project. So, you can try one of the following. i) tar packaging using maven-assembler plugin, or ii) convert it to spring-boot project if thats simpler and you could ,or iii) uber-jar creation using maven-shade plugin and need to make some configuration changes for not getting unpackaged to .class files. Still would suggest you can explore with the tar packaging option - (reference:) https://maven.apache.org/plugins/maven-assembly-plugin/

How to use jenkins to take a module maven project and turn it into a .jar

So I'm working on a java project located here. I have it on a jenkins server and I want it to compile all the different modules under one jar. I tried copying what another project did but am unable to produce a jar so I believe it has something to do with how I need to configure jenkins in order for it to make the jar. The jar doesn't need to be executable.
The maven-assembly-plugin can create your jar: https://maven.apache.org/plugins/maven-assembly-plugin/usage.html
Your project has 4 JARs and they don't depend on each other.
If NameLayer depends on NameLayer1_8_R1 you have to
add the dependency NameLayer1_8_R1 to the pom.xml of NameLayer and
the maven-assembly-plugin as descrbibed here to create a fat JAR (including all depending JARs).
Do the first step for as many dependencies as you need.

Maven: antrun plugin builds JAR file -> How can i install/deploy it in my repository?

I am in the middle of an Ant -> Maven migration project and I have a question (I'm not really a Maven expert), since I'm stuck at a particular point:
Within one of my pom.xml files I have to use the maven-antrun-plugin to call an external ANT file, which builds a jar file and puts it in a temporary folder. There is no alternative to this call. Everything is working fine - the ant script works as it should, but how can I "package" this jar in the usual Maven workflow?
I know that I could manually call the mvn install:install-file, but isn't there a possibility to configure my pom.xml in a way that the above generated jar file IS actually the artifact of that pom.xml?
you use the build helper maven plugin's attach artifact goal to attach your extra *.jar to the maven module that triggered its creation.
since having a single maven module produce more than one artifact is generally a bad idea it would be best if you isolate this in a maven module of type pom so that this would be its only artifact

Link maven dependencies on non maven project

I have two projects in Eclipse, the first project depends on maven, the second project which dependent on the first one does NOT depend on maven.
The first project downloads external libraries like jar files and natives to the .m2 maven folder. However the second project gives a ClassNotFoundException since it cant find the jar files and the native files from the first project.
Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties?
I would appreciate any help.
In your Maven project, use Assembly plugin to create an Uber-jar that contains the project build artifact and all its dependencies (mvn assembly:assembly -DdescriptorId=jar-with-dependencies). Then, reference that from project #2, either with a relative path or by using an ant build task to copy it into your other project's lib directory (assuming you have such a directory). Also, although it's frowned upon, you could configure the assembly plugin so that your Uber jar artifact always has the same finalName.
Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties?
I don't think so.
But maybe you could create a 3rd project (which is a Maven project) that depends on the first one, and on the JAR (or whatever) file created by the 2nd one as a non-repository dependency.
Having said that, anything you do is going to be a bit of a hack. You'd be better of either turning the 2nd project into a proper Maven project, or creating a custom build script that manually pulls the 2nd project's dependencies from somewhere. (I think that Ivy could help you with that ... assuming you use Ant in the 2nd project.)

How to generate an ear file from a maven-archetype-webapp artifact?

I currently have a project built with maven-archetype-webapp artifact. The default packaging for this project is war.
Is it possible for me to insert the maven-ear-plugin in this webapp pom.xml generate an ear file that contains this project war? I tried that, but the war file doesn't get embedded in the generated ear file. It has everything except the war file.
I read many Maven related articles, and perhaps I could use maven-archetype-j2ee-simple artifact. However, I'm reluctant to this use for 2 reasons:-
This artifact handles ejbs and all the extra features that I don't use. It makes my project looks bloated.
Second, it seems like it requires me to install the web module into the repository first before I can create the ear file. Is this the preferred way to create an ear file?
How do I create an ear file that contains the war file using maven-ear-plugin from my webapp's pom.xml? If this way is not possible, what's the preferred way?
I'm sorry if my questions sound a little novice, I realized I have whole lot more to learn about Maven.
Thanks much.
The maven ear plugin assumes that any WAR is a separate project, so you need two projects, plus a parent project. It's a function of how maven does packaging. Each project produces one artifact. There are ways around this, but Maven will punish you for your sins. This question goes into some detail on this topic.

Categories