WEB-INF/classes empty upon MavenBuild - maven

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

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.

Spring 2.2.1 Build error Could not find artifact com.fasterxml.jackson:jackson-bom:pom:2.10.5

I am new with Spring boot framework and I added spring-boot-starter-parent
am added spring-boot-starter-parent in my parent pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/>
</parent>
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>
<parent>
<groupId>Parent</groupId>
<artifactId>Parent</artifactId>
<version>7.0.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>Child</artifactId>
<packaging>pom</packaging>
<version>7.0.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.compiler.version>1.8</java.compiler.version>
<maven-jar-plugin.version>2.6</maven-jar-plugin.version>
<maven-surefire-plugin>2.19.1</maven-surefire-plugin>
<maven-assembly-plugin.version>2.5.5</maven-assembly-plugin.version>
<spring.version>4.1.7.RELEASE</spring.version>
<junit.version>4.11</junit.version>
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
<tomcat.version>8.5.12</tomcat.version>
<tomcat.8.0.version>8.0.50</tomcat.8.0.version>
<log4j.version>1.2.16</log4j.version>
<httpclient.version>4.5.3</httpclient.version>
<jackson.version>2.9.5</jackson.version>
<powermock.version>1.7.4</powermock.version>
<junit.version>4.11</junit.version>
<mockito.version>1.10.16</mockito.version>
<slf4j.version>1.7.5</slf4j.version>
<consul.version>0.14.0</consul.version>
<json.version>20080701</json.version>
<dom4j.version>1.6.1</dom4j.version>
<implementation.version>7.0.0.0</implementation.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.compiler.version}</source>
<target>${java.compiler.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifestEntries>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin}</version>
<configuration>
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
</plugins>
</build>
<modules>
</modules>
</project>
Now it's showing an error in pom.xml.
Project build error: Non-resolvable import POM: Could not find artifact com.fasterxml.jackson:jackson-bom:pom:2.10.5 in central (https://repo.maven.apache.org/maven2)
I tried following solutions
Update my maven project
remove and rebuild the .m2 folder
Please give suggestion on the above query.
The jackson-bom version that maven is trying to resolve is not in the maven repository.When i checked the latest version is version 2.10.1 . So, could you check if in your pom.xml anywhere you are explicitly setting the jackson version ? . If you try removing that and let maven resolve the version from spring.

Maven war doesn't have dependent jars and jsps

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>

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