Copy dependency to war before packaging - java

I'm packaging an ear file with maven for an IBM Content Navigator plugin project. This product requires to have an ear, which includes a war, and that war should include the plugin as jar in the root of the war. So not in the WEB-INF/lib. The ear and the war are just empty containers.
So I've created 3 projects, an ear, a web project, and a simple java project. All of these projects have a pom.
How can I create a war which includes the simple java project (jar) in the root of the war? It is not just a dependency as it must not end up in the WEB-INF/lib.
Thanks in advance,
Roeland Bestman

You need to use the maven-dependency-plugin's copy goal and place the jar in a directory under the target directory. Then you'll need to include it from there into your war using the maven-assembly-plugin.

Related

packaging a JAR file in root of WAR archive using maven

I'm trying to customise WAR archive generation with maven in a way that a certain client jar is at the root of a war file instead of default WEB-INF/lib directory
I used the copy goal of maven-dependency-plugin to copy this jar to location ${project.build.directory}${file.separator}${project.artifactId}-${project.version} this copies it as expected i.e. target/mywar-1.0-SNAPSHOT folder
\-target
|-mywar-1.0-SNAPSHOT
|-WEB-INF
|-lib
|-classes
|-something.jsp
|-other-jar-1.0-SNAPSHOT.jar
however, when the maven build generates a WAR archive this JAR is not included in the packaging in the root of WAR archive. How do I get the following WAR archive structure in place with maven?
\-mywar-1.0-SNAPSHOT.WAR
|-WEB-INF
|-lib
|-classes
|-something.jsp
|-other-jar-1.0-SNAPSHOT.jar
notice that this other jar should be at the same level as WEB-INF not inside it.
I would think the war plugin takes its input from the src directory, not the target directory. See the war-mojo docs.
What might help is this howto on how to add additional resources into the war file.

How to remove jar files from war file when deploying a java web application with jboss

I built my netbeans project and it created a .war file including all the .jar libraries. I need to remove my all libraries from .war file. I tried to untick them from library folder but then the project does not deployed. How can I remove my libraries from the .war file and if I remove them where should I put them correctly. In jboss also there is a folder called lib in standalone folder.Should I put them there? If so how to do it. I am not using maven.
If you are using Maven set the dependency scope to the libraries you would like omitted to have scope provided. You can add the dependencies of your WAR to the MANIFEST.MF file or the jboss-deployment-structure.xml file using Maven. If the lirbaries are not JBoss modules by default, eg Orcale JDBC driver, then you will need to create these modules yourself. See the JBoss AS 7 documentation on how to do this.
You can try following approach. I haven't worked on Jboss so don't have detail idea about it.
Deploy each logical library (like "OpenJPA" or "Log4J") as a module, including its api and impl jars and any dependency JARs that aren't already provided by other AS7 modules. If there's already a module add a dependency on it rather than adding a JAR to your module. If several different libraries share some common dependencies, split them out into modules and add them as module dependencies in module.xml.
Use jboss-deployment-structure.xml to have your deployment .war / .ear / whatever declare a dependency on the module if it isn't autodetected and autoloaded.
Courtesy #Craig Ringer.
For complete thread go here

How Can I have single project in Maven including EAR , WAR and EJB?

I am building this application for a client where one project folder with one pom file should consists all the EAR, WAR and EJB.
I found each of its own way in creating the project structure like http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/guide/Archetype/
How to create my own maven structure for this or are there any available archtype I can use?

Creating EAR file using Maven

I am facing an issue while creating EAR file using Maven of a Dynamic Web Project.
I have successfully created WAR file using POM.xml , but can anybody tell me how to write EAR script in POM.xml ?
Thanks in advance
It easy.
You need:
Root project, parent pom that have 2 modules - war and ear.
Move your war to war module
create ear module (add war as dependency)
You can use archetype:generate to create example of ear. For example archetype with id: 612.
612: remote -> org.jboss.spec.archetypes:jboss-javaee6-ear-webapp (An
archetype that generates a starter Java EE 6 webapp project for JBoss
AS 7. The project is an EAR, with an EJB-JAR and WAR)
If you don't need ejb - just delete it. In generated example ejb is optional.
Check my archetype for maven, this is for Java EE 6
https://github.com/sjpuas/jee6-archetype

How to add jars available in a particular folder to classpath at runtime only for specific wars:

I am using maven build tool.
The following two are my intentions.
1) To move some of the third party library jars out of my war from WEB-INF/lib folder [note: These jars are common between more than 2 war files (or artifacts)]
2) To make the war file small in size.
Is it possible to move those jars out of war and put it into a folder and these jars should be referred in the classpath only by the wars which require it.
I have tried adding the path to the jars in the Class-Path: of MANIFEST.MF of war files but it did not work out. Please help me out.
I assume the jars in question are necessary for compiling the code that make up the web application. If the third-party jars are necessary for compilation but you don't want them in your war file, you have two options:
In the <dependency></dependency> section for the third-party jar, add "<scope>provided</scope>".
Configure the maven war plugin to exclude the jars you don't want in the war. See http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html for the details.
How you get the jar files that you exclude from the war into the web container's classpath depends on your environment. If you are using ear files, the Maven docs above talk about how to get the jars included in the ear file. If you are not using ear files, you will have to come up with your own way to get the jars into the container's lib directory.

Categories

Resources