Create EAR with Maven and Eclipse - java

I have a web-application(TestWeb) and multiple java dependency projects(TestCommon,TestModule).
I was able to build all 3 projects using maven.It has created war file and jar file out of it.
I need to create .ear file using maven. How can I create ear and build them?
TestWeb/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>TestWeb</groupId>
<artifactId>TestWeb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>TestCommon</groupId>
<artifactId>TestCommon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>TestModule</groupId>
<artifactId>TestModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Use <packaging>ear</packaging> instead of <packaging>war</packaging>.

Related

add jsp to servlet and maven project

I want to add JSP files to servlet project using Maven
Here's 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>org.example</groupId>
<artifactId>time_table</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8085/manager/text</url>
<server>TomcatServer</server>
<path>/time</path>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</build>
How and where should I add JSP files?
and if I have some link to tutorials about this I'm very happy to check

alter pom file for heroku deployment

I'm trying to deploy an Eclipse jee dynamic web app to heroku. I need to modify the pom file but I'm not sure how.
Here's what I need to add but I'm not sure where to place:
<configuration>
<appName>gentle-shore-6874</appName>
</configuration>
here's the file from eclipse:
<?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>
<groupId>com.example</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.7.v20170914</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.7</version>
<configuration>
<buildpacks>
<buildpack>heroku/exec</buildpack>
<buildpack>heroku/metrics</buildpack>
<buildpack>heroku/jvm</buildpack>
</buildpacks>
</configuration>
</plugin>
</plugins>
</build>
</project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.7.v20170914</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.7</version>
<configuration>
<appName>gentle-shore-6874</appName>
<buildpacks>
<buildpack>heroku/exec</buildpack>
<buildpack>heroku/metrics</buildpack>
<buildpack>heroku/jvm</buildpack>
</buildpacks>
</configuration>
</plugin>
</plugins>
</build>
</project>

JAR generating with Maven

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>

error during building ear project with Maven 3

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

Maven - Unresolved references to [javax.activation, javax.annotation]

I'm developing web application with OSGI. I have a maven configuration error which I cannot find. This is the complete source code:
http://uploading.com/files/8e5c9888/SH_27_test.zip/
This is the POM file:
<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>org.DX_57.osgi.SH_27</groupId>
<artifactId>SH_27</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>SH_27-impl</artifactId>
<packaging>bundle</packaging>
<name>SH_27-impl</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>SH_27-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SH_27-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>${pom.groupId}.api, org.osgi.framework</Import-Package>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>${pom.groupId}.impl.SessionHandleApp</Bundle-Activator>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<groupId>org.DX_57.osgi.SH_27</groupId>
</project>
When I try to compile it with Netbeans I get this error:
http://pastebin.com/whxuSb7V
The problem occurs when I add #Datasource. It seems that I'm missing something in the POM file but I don't have idea what it is?
Any help will be highly appreciated.
Best Wishes
Peter
Check out Maven: Unresolved references to [org.osgi.service.http]. I think he had the same problem that he managed to resolve by including specific packages that need to be imported.
This is the solution:
<Import-Package>${pom.groupId}.api, org.osgi.framework</Import-Package>
Should be:
<Import-Package>*</Import-Package>
I hope that this will be helpful for someone.

Categories