My Maven EAR project packs my EAR with two copies of each of my libraries. One copy is always appended with the version (In my case 1.0-SNAPSHOT). Is there something screwed up in my POMs?
I keep getting these type of errors when i try and deploy to server:
Servlet [blah...] and Servlet [blah..] have the same url pattern: [/RegistrationService_V10].
My EAR project POM looks like this :
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>AlmexOffice</artifactId>
<groupId>com.huwag</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.huwag</groupId>
<artifactId>AlmexOffice-ear</artifactId>
<packaging>ear</packaging>
<version>1.0-SNAPSHOT</version>
<name>AlmexOFfice-ear JavaEE6 Assembly</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4</version>
<configuration>
<version>6</version>
</configuration>
</plugin>
</plugins>
<finalName>AlmexOffice-ear</finalName>
</build>
<dependencies>
<dependency>
<groupId>com.huwag</groupId>
<artifactId>AlmexOffice-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.huwag</groupId>
<artifactId>AlmexOffice-web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
In the maven-ear-plugin, you have to specify your ejbmodule and webmodule
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<ejbModule>
<groupId>com.huwag</groupId>
<artifactId>AlmexOffice-ejb</artifactId>
</ejbModule>
<webModule>
<groupId>com.huwag</groupId>
<artifactId>AlmexOffice-web</artifactId>
<contextRoot>/custom-context-root</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
Could you give us the feedback if it works better?
Related
I am trying to run a simple maven project from the mac terminal.
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>HelloWorld</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- here we specify that we want to use the main method within the Controller class -->
<mainClass>com.helloworld.Countries</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
I did maven package.
and when I try to run:
java -jar target/HelloWorld-1.0.jar
… I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONValue
Is the java.lang.NoClassDefFoundError only on macOS? I did the same project on Windows and it works fine.
Is there anyway that we can make this independent of OS?
Solution was to use Maven-shade-plugin. Here is my final 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>Helloworld</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.test.HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I get this error during generation of JAR with Maven:
Failed to execute goal on project TaskManagerTrue: Could not resolve dependencies for project groupId:TaskManagerTrue:jar:1.0: Could not find artifact groupId:TaskManagerTrue:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
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>
<groupId>groupId</groupId>
<artifactId>TaskManagerTrue</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>TaskManagerTrue</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<finalName>test</finalName>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<goal>jar:inplace</goal>
<archive>
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
</archive>
<outputDirectory>artifacts</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
How can I fix this problem?
Removing this declaration fixed the problem:
<dependency>
<groupId>groupId</groupId>
<artifactId>TaskManagerTrue</artifactId>
<version>1.0</version>
</dependency>
I am trying to configure the Maven Checkstyle Plugin for reporting and would like to change the dependency of Checkstyle to 7.5 instead of the default 6.11.2.
To achieve this I, have pluginManagement declared in parent pom with the dependency.
In the child project, I am just referencing the plugin in the reporting tag.
However I see that default Checkstyle (6.11.2) is being downloaded into the repository. Please see below parent and child 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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>parent_app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent_app</name>
<modules>
<module>my-app2</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Child pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>parent_app</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app2</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>src/main/resources/checkstyle.xml</configLocation>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
Can you please help if this is the right way to override dependency for reporting plugin? If so why is it not working?
Maven version: 3.2.5
It looks like there is a bug here with the Maven Site Plugin (a regression introduced after MSITE-507). The dependencies explicitly added to the managed plugins configured in the build are indeed not taken into account, unless the plugin is also declared itself. That is to say, the following in the parent POM will give you the wanted behaviour (tested with Maven 3.3.9):
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
When that new parent is installed in the local repository, and the build on the child is launched (with mvn clean site for example), it is the expected Checkstyle 7.5 that will be used.
How can I make a JAR file if project packaging type is "POM". The reason is that I have couple of sub-modules which added in this project. I'm using shaded plug-ins to make a JAR file but looks its not getting created in .m2 directory, but it creates in target folder which doesn't have any Classes, resources etc
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>HealthProject</groupId>
<artifactId>HealthProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>database</module>
<module>services</module>
</modules>
</project>
I would see following solutions.
Either you add to the other project the modules it depend on.
<dependency>
<groupId>HealthProject</groupId>
<artifactId>database</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>HealthProject</groupId>
<artifactId>services</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
or you create in HealthProject a new module which will create a Jar of HealthProject.
<parent>
<groupId>HealthProject</groupId>
<artifactId>HealthProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthproject-all</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>HealthProject</groupId>
<artifactId>database</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>HealthProject</groupId>
<artifactId>services</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
and then in the other project you add this as dependency.
<dependencies>
<dependency>
<groupId>HealthProject</groupId>
<artifactId>healthproject-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
</dependencies>
I have the tree
pom.xml
.presentation(ear)
..business(war)
..integration(jar)
when i try to build the ear (presentation) i get this error i don't understand why the artifact presentation should be a dependency and a dependency of what exactly ? :
Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.6:generate-application-xml (default-generate-application-xml) on project presentation: Artifact[war:presentaion:presentation] is not a dependency of the project. ->Help
ear: 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>presentation</groupId>
<artifactId>presentation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<parent>
<groupId>MyProject</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<modules>
<webModule>
<groupId>presentaion</groupId>
<artifactId>presentation</artifactId>
<bundleFileName>presentation.war</bundleFileName>
<contextRoot>/presentation</contextRoot>
</webModule>
<jarModule>
<groupId>integration</groupId>
<artifactId>integration</artifactId>
<bundleFileName>integration.jar</bundleFileName>
</jarModule>
</modules>
<displayName>My Project</displayName>
</configuration>
</plugin>
</plugins>
<finalName>presentation</finalName>
</build>
<dependencies>
<dependency>
<groupId>business</groupId>
<artifactId>business</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>integration</groupId>
<artifactId>integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
In the current .pom you are building an ear and you are giving the same ear as a warModule.
You should give a .war artefact for webmodule in the ear-plugin