Maven war doesn't have dependent jars and jsps - maven

I am completely new to build tools. I have to create a war using maven. My project has some dependent jars and jsps. but the resultant war doesn't have these jars and jsps.
Here is my project structure
TestWeb > src>main>webapp>WEB-INF>lib> all dependent jars
>src>main>webapp> all JSPs
Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>TestWeb</artifactId>
<version>1</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<packagingIncludes>src/main/webapp/*.jsp</packagingIncludes>
<packagingIncludes>src/main/webapp/WEB-INF/lib/*.jar</packagingIncludes>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>

Related

Maven assembly plugin - ignore 'archive cannot be empty'

I have problem with assembly plugin. I have to use one assembly definition which create JAR file for more modules. So project structure looks like this
module/
----module1/
-------- pom.xml
----module2/
-------- pom.xml
----moduleX/
-------- pom.xml
assembly_jar.xml
pom.xml (this is parent)
Parent pom file looks like following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.project</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>false</attach>
<descriptors>
<descriptor>${source-systems.basedir}/assembly_jar.xml</descriptor>
</descriptors>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</plugin>
</plugins>
</build>
</project>
assembly_jar.xml looks like following:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>jar-with-some-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
<unpack>true</unpack>
</dependencySet>
</dependencySets>
</assembly>
pom file of module 1 looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.my.project</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
<groupId>com.my.project</groupId>
<artifactId>module1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>oracle_rds</name>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
</dependencies>
</project>
When I run mvn clean install for module1 everything works fine and jar file is created. But then I have module2 which does not need any particular dependencies. So pom file looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.my.project</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
<groupId>com.my.project</groupId>
<artifactId>module2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>oracle_rds</name>
</project>
When I run mvn clean install I have error Error creating assembly archive jar-with-some-dependencies: archive cannot be empty It is because there is no dependency to pack into jar file.
Is there any way how to ignore this error and do not create jar file if there are not dependencies in module?
I do not want to move assembly definition into module because of big duplicity (I will have more then 100 modules and mostly of them will have some special dependencies)
Thanks for help.

WEB-INF/classes empty upon MavenBuild

I am building a multi modules project the hierarchy for it as follow :
ParentProject
|_ WebModule
|_src
|_main
|_ java
| |_Some packages here
|_webapp
|_EARModule
|_ EJBModule
|_ JARModule
Mvn clean install command is working perfectly fine and i can find the generated EAR file. Inside the EAR i can see the EJB module and the JAR module are created and compiled as well, but for the web module the WAR is created with correct structure but the class directory is empty !
I am using Maven2 and JAVA7
the parent POM is :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>XXXX</groupId>
<artifactId>parentModule</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>EJBModule</module>
<module>EARModule</module>
<module>JARModule</module>
<module>WEBModule</module>
</modules>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<!--Project dependencies-->
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
EAR POM :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ParentModule</artifactId>
<groupId>XXXX</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>ear</packaging>
<artifactId>EARModule</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<modules>
<webModule>
<groupId>XXXX</groupId>
<artifactId>WebModule</artifactId>
<bundleFileName>abc.war</bundleFileName>
<contextRoot>/abc</contextRoot>
</webModule>
<ejbModule>
<groupId>XXXX</groupId>
<artifactId>EJBModule</artifactId>
<bundleFileName>ejbModule.jar</bundleFileName>
</ejbModule>
</modules>
<displayName>theEar</displayName>
<generateApplicationXml>true</generateApplicationXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--some dependencies-->
</dependencies>
</project>
WEB app POM :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parentModule</artifactId>
<groupId>XXXX</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>WebModule</artifactId>
<packaging>war</packaging>
<name>abc</name>
<dependencies>
<!-- some dependencies -->
</dependencies>
</project>
Note : These pom files are samples to demonstrate my case.
The problem was not in the POM files. the actual issue is that i copied source code under src/main/java directory but it was having some compilation issues.
I am using IntelliJ IDE, unfortunately, IntelliJ is not notifying me after copying the source code (even after synchronize the project). So what i did is just right click on the web module then clicked on Build module <'module name'> which shows the compilation error. After rectifying the issues then run
mvn clean install
I could find the classes get generated in the war.
I hope this help somebody

How to deploy a war in an specific path jboss as 7.4 using jenkins and jboss-as?

im trying to deploy a war file to jboss-AS 7.4, but when i run the deploy, the plugin deploy the war file genetated by the plugin,what i need is that the plugin deploys a war file in a specific directory of my system, this is my pom.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ss</groupId>
<artifactId>ss</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>ss</name>
<description>uses the pom to deploy to Jboss AS 7 with jenkins</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
<hostName>localhost</hostName>
<jbossUser>user</jbossUser>
<jbossPass>admin</jbossPass>
<warName>ss</warName>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<configuration>
<force>true</force>
<hostname>${hostName}</hostname>
<username>${jbossUser}</username>
<password>${jbossPass}</password>
<port>10000</port>
<fileNames>
<fileName>${warName}.war</fileName>
</fileNames>
<name>ss.war</name>
</configuration>
</plugin>
</plugins>
</build>
assuming that the war file is in the same directory as the pom, how can i make this work?
Thanks for your answers.
Reading the plugin documentation, it looks like you have to set the targetDir to the target directory where you want your application to be deployed link
Default: ${project.build.directory}/
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<configuration>
<force>true</force>
<hostname>${hostName}</hostname>
<username>${jbossUser}</username>
<password>${jbossPass}</password>
<port>10000</port>
<fileNames>
<fileName>${warName}.war</fileName>
</fileNames>
<name>ss.war</name>
<targetDir>src/custom/path/</targetDir>
</configuration>
</plugin>
hope it helps
Well i found a solution and apparently the problem be really small, the problem was that i was using a different property inside the configuration tags, this is the pom that worked for me:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cc</groupId>
<artifactId>cc</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>cc</name>
<description>uses the pom to deploy to Jboss AS 7 with jenkins</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<configuration>
<hostname>localhost</hostname>
<username>user</username>
<password>pass</password>
<port>10000</port>
<filename>mywar.war</filename>
</configuration>
</plugin>
</plugins>
</build>
the change made is that I delete the tags fileNames and fileName and add the property filename, here you can specify the path to the war file to be deployed in the server ignoring the generated war in the target directory.
Thanks to all.

Maven Project URL

I have made a EAR project with Maven in NeatBeans IDE running on Glassfish, and a problem with default URL of the project, instead of loading:
http://localhost:8080/Opine-war
is loading
http://localhost:8080/Opine-war-1.0-SNAPSHOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-application PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Java EE Application 6.0//EN" "http://glassfish.org/dtds/glassfish-application_6_0-1.dtd">
<glassfish-application>
</glassfish-application>
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>Opine</artifactId>
<groupId>br.edu.infnet</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>br.edu.infnet</groupId>
<artifactId>Opine-ear</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>
<name>Opine-ear</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>br.edu.infnet</groupId>
<artifactId>Opine-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>br.edu.infnet</groupId>
<artifactId>Opine-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
I think there are two options. One is to change the finalName inside the pom.xml:
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
above shows the default.
Another option is to change the context name of your application which is currently derived from the ear file name. But the deployed ear does not need to match the context name (which you want to be "Opine-war"?
You can customize this within the ear plugin (which is enabled if you use <packaging>ear</packaging>: https://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-context-root.html

when installing artifact *zip file doesn't appear in local repo

I have project with some configuration files and after run maven install I got *.zip archive in target directory. However in my local repo I have only pom file. I auusme it's because of <packaging>pom</packaging> drfined in pom.xml. How can I get *.zip file in local repo anyway?
Here is the pom
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycomp.name</groupId>
<artifactId>saas-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../saas-parent/pom.xml</relativePath>
</parent>
<!-- TEST -->
<artifactId>htdocs</artifactId>
<name>htdocs</name>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<goals><goal>single</goal></goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>

Resources