I have a project bird with the following components in pom.xml
<groupId>com.myorg</groupId>
<artifactId>bird</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>bird</name>
<modules>
<module>persistence</module>
<module>business</module>
<module>service</module>
<module>web</module>
</modules>
and the web module pom.xml
<parent>
<artifactId>bird</artifactId>
<groupId>com.myorg</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<packaging>war</packaging>
The web module creates a war file named web-1.0-SNAPSHOT.war
How can I configure maven to build it as bird.war?
You can use the following in the web module that produces the war:
<build>
<finalName>bird</finalName>
. . .
</build>
This leads to a file called bird.war to be created when goal "war:war" is used.
You need to configure the war plugin:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>bird.war</warName>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
More info here
Lookup pom.xml > project tag > build tag.
I would like solution below.
<artifactId>bird</artifactId>
<name>bird</name>
<build>
...
<finalName>${project.artifactId}</finalName>
OR
<finalName>${project.name}</finalName>
...
</build>
Worked for me. ^^
You can follow the below step to modify the .war file name if you are using maven project.
Open pom.xml file of your maven project and go to the tag <build></build>,
In that give your desired name between this tag :
<finalName></finalName>.
ex. : <finalName>krutik</finalName>
After deploying this .war you will be able to access url with:
http://localhost:8080/krutik/
If you want to access the url with slash '/' then you will have
to specify then name as below:
e.x. : <finalName>krutik#maheta</finalName>
After deploying this .war you will be able to access url with:
http://localhost:8080/krutik/maheta
Related
I am trying to mavenize an existing project.
I was able to build the EAR file(since i have to deploy in Websphere), When I try to deploy, using admin console - Able to install successfully , But application is not working, After investigating, I found the class files size is very less compare to the reference EAR file(old existing EAR file)
Steps I followed to build the EAR file
M2E plugin installed
Configure to Maven
Add ALL the jar files from lib folder like below(I read in SO, this is not the recommended way, but to complete the project, I have to do this)
<dependency>
<groupId>JarFile</groupId>
<artifactId>JarFile</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/CRDBXMLExternal.jar</systemPath>
</dependency>
Added the relevant plugins (war, EAR)
Clean Build and Install.
ear file created. ear contains a war file, which has all the project related files including class,jsp etc.
I compared the folder structure with the existing EAR file and its contents , all look good. But only the size of class files(Not ALL but more than 80%) are varying. I use JD to decompile and see the code, Most of the code are not present, including imports.
If anyone has encountered similar issue , could you please tell me what am doing wrong here.
More Info
there are two project folders(both are maven) one will create WAR and another one EAR in EAR pom.xml
there is a dependency
<dependency>
<groupId>com.comp.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
Then there is a plugin
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<generatedDescriptorLocation>C:\COMP\Dev\may\repos\0.0.1-SNAPSHOT</generatedDescriptorLocation>
</configuration>
</plugin>
</plugins>
</build>
Adding WAR file building(Removed most of the dependencies kept only one sample) 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.comp.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>ABC</name>
<description>ABC</description>
<dependencies>
<!-- Local Repository -->
<dependency>
<groupId>com.ibm.ws.runtime</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/com.ibm.ws.runtime.jar</systemPath>
</dependency>
</dependencies>
<repositories>
<repository>
<id>nexus-releases</id>
<name>nexus</name>
<url>http://abc-nexus.ldn.xyz.com:9080/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- <warSourceDirectory>${project.basedir}\WebContent</warSourceDirectory> -->
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
The above does not tell Maven to package the EAR file with the lib directory dependency. It actually tells it to create local dependency on an existing JAR that is provided only at compile time. Thus, when you export the EAR, it does not include any of the JARs because it assumes that they are provided at runtime.
You should use the maven-ear-plugin which package an EAR file instead. You can find the full documentation here.
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.1</version>
</plugin>
The issue was,
web/WebContent/WEB-INF/classes is not getting updated.
but I could see the latest classes under web/target/classes path.
Now am checking why web/WebContent/WEB-INF/classes is not getting updated.
Just now got the Resolution from the below Link :-
ISSUE SOLVED by with the help of
https://coderanch.com/t/474423/ide/ecplise-doesn-create-classes-folder
Steps
Right click on your project -> build path -> Configure build path -> click on source tab -> click on browse (Default output folder).
After browsing click on WebContent -> Select WEB-INF -> Create new folder (called classes). it will open new window.
Give folder name as classes. Click on Advanced and give path of current classes folder means WEB-INF/classes.
After doing this, eclispe will rebuild your project and classes will be genenrated at WEB-INF/classes directory.
I'm creating a war file from a simple Spring boot (1.x) project, and I would like to modify the Context path.
For that purpose, I have an application.properties file that looks like this:
server.contextPath=/newpath
The project structure is the following:
.
src
main
...
resources
application.properties
The pom.xml 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.api</groupId>
<artifactId>example</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test project</name>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.5.9.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>example</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I perform a mvn package, I get a WAR file with the application.properties file located in /WEB-INF/classes, same content as the one I wrote. However, when deploying the war to Tomcat, I cannot access my API thru:
localhost:8080/newpath/example/some_controller
I can only query it via:
localhost:8080/example/some_controller
Am I missing something?
The server.context-path property only affects an embedded container. When deployed to an external container the context path is determined differently.
In the case of Tomcat, you could copy your application to the webapps directory as a file named newpath.war. It should then be available at localhost:8080/newpath/example/some_controller.
Please make sure you converted spring boot executable jar project into war file , there are three steps to convert to war file. Please follow steps given in this url -
https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/
I would to know if a war file created using maven package phase would be equal to a war file created using maven war plugin war:war goal.
Assuming we have a pom.xml (extract) like this:
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
...
I mean, it's necessary to have the plugin to build a war file (with no special restriction or feature). Please fee free to add any comment or suggestion. Thanks in advance
They are absolutelly equal. The purpose of plugin block with maven-war-plugin description is - for example - change default webappDirectory value. See more: http://maven.apache.org/plugins/maven-war-plugin/usage.html
im working on a web application with maven and Jboss 7 wich conatins 3 modules ejb ear and war so the war will have the ejb as dependancy and the ejb will be in the same time a module of the ear so when i do this i get the same ejb twice this tree
ear
...Mywar
........Myejb
...Myejb
is this structure is correct or i should change another
the pom.xml for the war :
<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>tn.war.ep</groupId>
<artifactId>businessModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
.....
<dependency>
<groupId>tn.linckia.epgp</groupId>
<artifactId>ejbModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
</project>
the pom.xml for the ear :
<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>tn.war.ep</groupId>
<artifactId>earModule</artifactId>
<version>0.0.1</version>
<packaging>ear</packaging>
<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>tn.war.ep</groupId>
<artifactId>businessModule</artifactId>
<bundleFileName>businessModule.war</bundleFileName>
<contextRoot>/businessModule</contextRoot>
</webModule>
<ejbModule>
<groupId>tn.war.ep</groupId>
<artifactId>ejbModule</artifactId>
<bundleFileName>ejbModule.jar</bundleFileName>
</ejbModule>
</modules>
<displayName>Security</displayName>
</configuration>
</plugin>
</plugins>
<finalName>AuthModule</finalName>
</build>
<dependencies>
<dependency>
<groupId>tn.war.ep</groupId>
<artifactId>businessModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>tn.war.ep</groupId>
<artifactId>ejbModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
</project>
Right way to configure EAR Module is to have the EJB jar dependency with "provided" scope in WAR module and having EJB jar directly under EAR like the below:
EAR
|
|-lib/someutil.jar
|-EJB.jar
|-my-web.war
| |-WEB_INF/lib
| |-coolutil.jar
|-EJB2.jar
But the my-web.war can dependent on the any EJB.jar, but its resolved in runtime by container. So, mark that ejb dependency as "provided" (by container) in WAR's pom.xml.
Option : #1
Yon don't even need a ear.
You can just put all your EJBs as jars inside the war.
Just add the EJB projects as dependencies in your War project.
Option : #2
If you still want EAR. All EJB projects output should be jars. And web project output should be war. And at last these EJB jars and web war would be placed in one EAR. This is a old fashion way, to keep it simple you could follow the method which I explained above in Option #1.
I had this issue and changing the ejb packaging tag from ejb to jar in the ejb modules pom.xml fixed the issue. No idea why!
How do I get Maven to create an appropriately named .war for use with Tomcat 7's parallel deployment feature?
More generally, how do I manipulate the filename of the .war mvn produces?
Tomcat 7 wants a .war named app##V001 for use with the parallel deployment feature.
Ideally, I'd want it to use the date for the version number, rather than having to rely on a hardcoded version number anywhere.
Pom.xml to create test jar 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>
<groupId>com.yoursPath.core</groupId>
<artifactId>MyFirstJarThruMaven</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>MyFirstJarThruMaven</name>
<url>http://maven.apache.org</url>
<properties>
<jdk.version>1.6</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
If you run the code maven package now, Maven will package this Java project into a jar file named “MyFirstJarThruMaven-1.0.jar“, in target folder.