how to create deployable war in spring using maven - spring

Creating war in spring what are the dependency needed ?
1) maven compiler and maven war plugins are required ?
2) How to add class path reference to war package ?

Create a Maven Spring project and in pom.xml change the packaging to war:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>Maven Spring Project</artifactId>
<packaging>war</packaging>
And just build the project using Maven by executing goal : "clean install". It will automatically create war file in target folder of Maven project.

You can try this in your pom.xml
<build>
<finalName>projectname</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>${jdk-version}</source>
<target>${jdk-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>-XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
</plugins>
</build>
and to make war run this package tomcat7:run goal from eclipse

Related

PluginVersionResolutionException in Maven project when I set packaging to bundle

In my Maven project when I change the packaging type from 'jar' to 'bundle' most of my plugins (compiler, deploy, install, resources, surefire) lose their versions. Why is this?
My pom.xml is below:
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ui_4.4.35_patch</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>web.admin.*</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
There are two possible approaches. The one I use for my own projects is to keep the bundle packaging and add the maven plugin versions to a pluginManagement section in the pom.xml. For example:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<!-- Add you current 'plugins' section here. -->
</build>
In addition to the version, you can also add configuration to each plugin. If your project has a parent pom, it would be natural to add the pluginManagement section there instead of in your bundle module.
Alternatively, as suggested by #khmarbaise, you can use jar packaging and just use the maven-bundle-plugin to generate the manifest. That approach is described in the plugin documentation page.

RED5. Maven deploy issue

I am trying to publish an spring mvc application in Red5Pro server. (tomcat).
I use Maven as build tool, but it seems to not work properly, because the
compiled classes are not found in WEB-INF/classes. This is my project structure:
The project is found in RED5ProHome/webapps, but without the compiled classes. (only xml, jsp and html).
This is my pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>org.red5.example</groupId>
<artifactId>springmvc</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<build>
<finalName>springmvc</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<dependencies>
// all dependencies needed
</dependencies>
Another point is that I export my project as war, manually, it works.
Do you have any idea how can I solve this issue?
Thank you.

Java 1.4 used with maven jar plugin?

In some of my maven modules (example myChild) I use maven-jar-plugin to create some additional jar, named here my-plugin.jar. This my-plugin.jar should be only the part of the entire module - myChild.jar.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=...>
<modelVersion>4.0.0</modelVersion>
<artifactId>myChild</artifactId>
<parent>
<groupId>org.group</groupId>
<artifactId>myParent</artifactId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>build-plugins-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<includes>
<include>......</include>
</includes>
<finalName>my-plugin</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
...........
</dependencies>
When I want to use myChild module in the another maven module (example myExternal) I add the dependency on myChild. But the compilation of myExternal failed because of errors like: method does not override or implement a method from a supertype. When I removed two #Override annotations, the number of errors decreased by two. It seems that Java 1.4 is used. But parent POM has maven-compiler-plugin with source and target 1.7.
What more is curious, the myChild module compiles well. But when some other module which uses myChild is compiling, then the above errors occurs.
Ok, according to published code you need to move maven-compiler-plugin configuration from plugins to pluginsManagement sections to be visible in all submodules.
Parent POM sample configuration
<pluginManagement>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</pluginManagement>

maven-war-plugin always running even without child pom.xml reference...why?

I am specifying:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>C:\apache-tomcat-7.0.42\webapps</outputDirectory>
</configuration>
</plugin>
.
.
.
However, even though I do not specify anything in the respective children pom.xml, the war file is still being moved to that output directory.
As far as I know, pluginManagement is only there for reference from the children pom right?
Thank you for your help
By default Maven will invoke the maven-war-plugin war:war goal as part of the package phase if you specify <packaging>war</packaging> in your pom.xml
Since you have a <pluginManagement> stanza for maven-war-plugin specifying a custom <outputDirectory> in your parent pom.xml your child pom.xml will use this property when you run the package phase.
http://maven.apache.org/plugins/maven-war-plugin/usage.html

I changed <packaging>war</packaging> to <packaging>pom<packaging>, but I am getting an error

I have changed war to pom, but I am getting the following error:
Project configuration is not up-to-date with pom.xml.
Run Maven->Update Project or use Quick Fix.
How can I solve this error?
Assuming you are using Eclipse, you right click the pom, choose Maven --> Update Project.
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
br.com.projetoweb03
universo2
0.0.1-SNAPSHOT
war
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>

Resources