Does anyone know of any web applications that are built with Maven to an RPM? The RPM Maven Plugin provides the functionality to build to an RPM, but it's documentation is lacking.
Specifically, I'm looking for an example that would include multiple modules, i.e. Chapter 8. A Multi-module Project, from the "Maven by Example" series.
An example with only a single module would be:
<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.mycompany.app</groupId>
<artifactId>my-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SOME-SNAPSHOT</version>
<name>my-webapp</name>
<url>http://maven.apache.org</url>
<properties>
<rpm.install.basedir>/opt/tomcat6</rpm.install.basedir>
<rpm.install.webapps>${rpm.install.basedir}/webapps</rpm.install.webapps>
<rpm.install.config>${rpm.install.basedir}/lib</rpm.install.config>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
<!-- Jackson JSON Processor -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-1</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>attached-rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<copyright>My Company</copyright>
<distribution>My Distribution</distribution>
<group>Applications/Internet</group>
<packager>${user.name}</packager>
<changelogFile>CHANGELOG</changelogFile>
<defaultDirmode>500</defaultDirmode>
<defaultFilemode>400</defaultFilemode>
<defaultUsername>tomcat6</defaultUsername>
<defaultGroupname>tomcat6</defaultGroupname>
<requires>
<require>apache-tomcat >= 6.0.20-2</require>
</requires>
<mappings>
<!-- webapps deployment -->
<mapping>
<directory>${rpm.install.webapps}/${project.artifactId}</directory>
<sources>
<source>
<location>target/${project.artifactId}-${project.version}</location>
</source>
</sources>
</mapping>
<!-- configuration files -->
<mapping>
<directory>${rpm.install.config}</directory>
<configuration>true</configuration>
<sources>
<source>
<location>src/main/resources/my-webapp.jdbc.properties.sample</location>
</source>
<source>
<location>src/main/resources/my-webapp.runtime.properties</location>
<destination>my-webapp.runtime.properties.sample</destination>
</source>
</sources>
</mapping>
<!-- (Optional) Create other necessary directory structure -->
<mapping>
<directory>${rpm.install.basedir}/my-webapp-workspace</directory>
<filemode>750</filemode>
<username>tomcatuser</username>
<groupname>tomcatuser</groupname>
</mapping>
</mappings>
<!-- (Optional) -->
<preinstallScriptlet>
<scriptFile>src/main/scripts/rpm/pre-install.sh</scriptFile>
</preinstallScriptlet>
<!-- (Optional) -->
<postinstallScriptlet>
<script>echo "WARNING: Restart tomcat to ensure changes take effect."</script>
</postinstallScriptlet>
</configuration>
</plugin>
</plugins>
</build>
</project>
Thanks for any/all help!
So, it turns out the example that I gave in asking my question was quite wrong, which probably contributed to why I didn't get the complete answer I was looking for. What I was really looking for was an RPM to install to a server, that depended on a servlet container (i.e. Tomcat) and would install the included Web Applications (webapps) to Tomcat's webapps directory.
As such, here is the proper answer:
<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.mycompany.app</groupId>
<artifactId>rpm-with-webapp</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>application-master-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<rpm.install.basedir>/srv/apache-tomcat-6.0.33</rpm.install.basedir>
<rpm.install.webapps>${rpm.install.basedir}/webapps</rpm.install.webapps>
<rpm.install.config>${rpm.install.basedir}/lib</rpm.install.config>
</properties>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>build-rpm</id>
<activation>
<property>
<name>build-rpm</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-1</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>attached-rpm</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
<configuration>
<classifier>${rpm.classifier}</classifier>
<copyright>My Company</copyright>
<distribution>My Distribution</distribution>
<group>Applications/Internet</group>
<packager>${user.name}</packager>
<changelogFile>CHANGELOG</changelogFile>
<defaultDirmode>500</defaultDirmode>
<defaultFilemode>400</defaultFilemode>
<defaultUsername>tomcatuser</defaultUsername>
<defaultGroupname>tomcatuser</defaultGroupname>
<requires>
<require>apache-tomcat >= 6.0.20-2</require>
</requires>
<mappings>
<!-- web app 1 (module #1) -->
<mapping>
<directory>${rpm.install.webapps}/myWebApp1</directory>
<sources>
<source>
<location>../path-to/myWebApp1/target/myWebApp1</location>
</source>
</sources>
</mapping>
<!-- web app 2 (module #2) -->
<mapping>
<directory>${rpm.install.webapps}/myWebApp2</directory>
<sources>
<source>
<location>../path-to/myWebApp2/target/unified-browser-widget</location>
</source>
</sources>
</mapping>
<!-- web app 3 (module #3) -->
<mapping>
<directory>${rpm.install.webapps}/myWebApp3</directory>
<sources>
<source>
<location>../path-to/myWebApp3/target/report-services</location>
</source>
</sources>
</mapping>
</mappings>
<postinstallScriptlet>
<script>echo "WARNING: You may need to restart tomcat to ensure changes take effect."</script>
</postinstallScriptlet>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
The thing to note about this is that I was looking for a "multi-module" project, but really what I meant was packaging multiple related Web Applications into a single RPM. So, the proper configuration of this Maven build tells the RPM installer that Apache Tomcat is required and installs the webapps to the proper folder within Tomcat.
I would suggest making the rpm a separate project (even if part of a multi-module) and have it declare dependencies on the war(s) or additional artifacts provided by other projects.
As far as I know Red Hat is working hard to deliver their Java projects (POM) in Fedora (RPM). Good example could be JBoss Application Server 7 which is being packaged for Fedora right now. Its a big bunch of POM files that are being translated from POMs to RPMs using various techniques and RPM macros. Those RPMs are somehow Maven-compatible. I don't know many details, but feel free to ask on lists/irc channels.
But my message is - generally it is not possible to use a "translator" that would read a set of pom files and produced set of rpm files. There are snags, you have to package everything one by one by hand.
If your target is not to do it the clean way, you could distribute your app in an one big RPM. Its pretty easy to create binary-only rpm. But this is not the way how open-source is delivered in linux distributions.
Related
I am trying to do an excercise with micro-services in Java with Spring boot, for this I am developing two web services in different projects with the intention of deploying them in tomcat like two independent files (.war).
I have read about set up tomcat to have the dependencies in an specified folder to share it with other services and this way not to increase the same libraries in all services.
The ploblem is that when I compiled the service with maven through the artifact spring-boot-maven-plugin the .war files always has the dependencies inside. Because of I want to know if someone know how to configure maven to
remove dependencies from .war file..... in Spring Boot.
The .war follows with the dependencies inside, Edited:
I have added the provided like said Michael Potter and the execution. it works fine. My pom.xml is the follow:
<?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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo1</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
For Maven not to include dependency in your WAR file you need to specify its scope to provided. The description of the scope from official Maven documentation:
This is much like compile, but indicates you expect the JDK or a
container to provide the dependency at runtime. For example, when
building a web application for the Java Enterprise Edition, you would
set the dependency on the Servlet API and related Java EE APIs to
scope provided because the web container provides those classes. This
scope is only available on the compilation and test classpath, and is
not transitive.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
<scope>provided</scope>
</dependency>
The dependency will be downloaded to compile the sources, but not packed in the WAR.
Concerning spring-boot-maven-plugin. By default it makes repackaging of a WAR that allows you to launch it from console. Thus, it packages all required dependencies to the archive - even with the provided scope. You can see in your target directory two files: {project-name}.war which is repackaged and {project-name}.war.original - the one that should not contain provided dependencies. To disable repackaging you should change spring-boot-maven-plugin configuration to the following:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
Then you need to place the required dependency to tomcat/lib folder and restart the Tomcat.
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>com.edi.proiecte</groupId>
<artifactId>Livada</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Livada</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.eirslett/frontend-maven-plugin -->
<dependency>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/exec-maven-plugin -->
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.webjars.npm/bower -->
<!-- https://mvnrepository.com/artifact/org.webjars.npm/bower -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<!-- optional -->
<configuration>
<workingDirectory>client</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<extensions>true</extensions>
<executions>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually
"install", so unless you need to run some other bower command,
you can remove this whole <configuration> section.
-->
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run Grunt's default
task (and you can remove this whole <configuration> section.) -->
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<!-- optional -->
<configuration>
<installDirectory>C:\Program Files\nodejs</installDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<attachClasses>true</attachClasses>
<webResources>
<resource>
<directory>${project.build.directory}/client</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
This is my pom.xml. I am trying to deploy a template to a Tomcat server, and then make a basic CRUD example for the client with angular for the frontend, hibernate for persisting objects in the database. I have created my project using the spring initializr that they provide online at https://start.spring.io/ Basically what i have to do is demonstrate a simple proof of concept to the client. My problem is the config file for maven. I am trying to use the frontend-maven-plugin to run grunt and bower and build my project into a WAR file that I can deploy on a Tomcat server. I have been fiddling around with the config file for 2 days trying to get it to work, and I have to get the thing going for today at 02:00 PM when the client will come in to see what we have done. I have made some progress, but I still get an error when bower is supposed to install:
Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.4:bower (bower install) on project Livada: Failed to run task: 'bower install' failed. java.io.IOException: Cannot run program "C:\Program Files\nodejs\node\node.exe" (in directory "E:\IntelliJ_IDEA\projects\LIVADA\client"): CreateProcess error=2, The system cannot find the file specified -> [Help 1]
Been resolving a lot of cryptic errors like this, but from what I can see, I did just like the Github page of the creator showed me to configure the frontend maven plugin: https://github.com/eirslett/frontend-maven-plugin
Sometimes IntelliJ even sabotaged me and would not want to run some goals, so I had to Invalidate Caches and restart the IDE.
I made another post 2 days ago, and I tried to follow the instructions that have been given in the response as close as I could, but to no avail.
Spring + Hibernate + Angular + Maven + Tomcat Project folder structure issues
My project structure is as follows:
LIVADA - E:\IntelliJ_IDEA\projects\LIVADA
.idea
libraries
.name
compiler.xml
encodings.xml
misc.xml
modules.xml
workspace.xml
.mvn
wrapper
maven-wrapper.jar
maven-wrapper.properties
client
.idea
misc.xml
modules.xml
sb-admin-angular-master.iml
workspace.xml
app
js
sb-admin-2.js
scripts
controllers
chartController.js
form.js
main.js
directives
chat
chat.html
chat.js
dashboard
stats
stats.html
stats.js
header
header-notification
header-notofication.html
header-notification.js
header.html
header.js
notifications
notifications.html
notifications.js
sidebar
sidebar-search
sidebar-search.html
sidebar-search.js
sidebar.html
sidebar.js
timeline
timeline.html
timeline.js
app.js
styles
main.css
sb-admin-2.css
timeline.css
views
dashboard
home.html
main.html
pages
blank.html
login.html
ui-elements
buttons.html
grid.html
icons.html
notifications.html
panels-wells.html
typography.html
chart.html
form.html
table.html
.buildignore
.htacess
404.html
favicon.ico
index.html
robots.txt
test
spec
controllers
about.js
main.js
.jshintrc
karma.conf.js
.gitignore
bower.json
Gruntfile.js
LICENSE
package.json
README.md
src
main
java
com.edi.proiecte.Livada
LivadaApplication.java
resources
application.properties
test
java
com.edi.proiecte.livada
LivadaApplicationTests.java
.gitignore
Livada.iml
mvnw
mvnw.cmd
pom.xml
Maybe I screwed up the folder structure, but i can't see how, as I configured the WAR plugin to copy files from the client folder and put them in the WAR file. Any help is greatly ppreciated. Thanks.
UPDATE
Solved that, for some reason the pom.xml reads C:\nodejs\node\node.exe, so i made a shortcut there. but I still get the error: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.4:bower (bower install) on project Livada: Failed to run task: 'bower install' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
I tried to integrate PMD in one of my project (I am using MAVEN Build tool)
When I try to integrate, I can see XML configuration files are mandatory.
I have tried to download PMD plugin - I expected global ruleset files might be available in PMD plug in, but they are not.
I used below link:
https://sourceforge.net/projects/pmd/?source=typ_redirect
After googling, I have seen one link to get ruleset
http://grepcode.com/file/repo1.maven.org/maven2/pmd/pmd/4.3
I cant download all XML files.
Is there any way to download/update through build or can we get all XML files in one location anywhere? I tried my level best to search in google and couldn't figure it out.
I attached pom.xml here. Can you please let me know how to add my ruleset automatically whenever PMD updated automatically?
<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.scm</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SCM-PRODUCT</name>
<description>SCM Product for learning purpose</description>
<properties>
<java.version>1.7</java.version>
<hibernate.validator.version>5.2.4.Final</hibernate.validator.version>
<javax.el-api.version>2.2.4</javax.el-api.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle-config-url>
D:/rules/checkstyle/2.0/checkstyle-2.0.xml
</checkstyle-config-url>
<checkstyle.version>6.18</checkstyle.version>
<log4j.version>1.2.17</log4j.version>
<!-- TEST CASES RELATED BEGINS-->
<junit.version>4.12</junit.version>
<!-- TEST CASES RELATED ENDS HERE-->
<!-- STATIC CODE ANALYSIS PROPERTIES -->
<findbugs.plugin.version>3.0.3</findbugs.plugin.version> <!-- Reports on common code mistakes and pitfalls -->
<checkstyle.plugin.version>5.0</checkstyle.plugin.version> <!-- Checks Code Style for Developers -->
<pmd.plugin.version>3.6</pmd.plugin.version> <!-- Source Code Analyzer -->
<doxia.module.markdown.version>1.3</doxia.module.markdown.version>
<javadoc.plugin>2.8.1</javadoc.plugin> <!-- Generates JavaDoc -->
<jxr.plugin>2.3</jxr.plugin> <!-- Cross reference report of project source code -->
<!-- REPORTING TOOL PROPERTIES -->
<project.info.reports.plugin>2.4</project.info.reports.plugin> <!-- A plethora of miscellaneous report: info, ci, dependencies, scm, plugins, etc. -->
<site.plugin>3.1</site.plugin>
<sonar.plugin>3.2-RC3</sonar.plugin> <!-- Analysis and metrics on code over time -->
<surefire.plugin>2.12</surefire.plugin> <!-- Reports Test Results -->
<taglist.plugin>2.4</taglist.plugin> <!-- Reports on Tags such as #todo and //TODO -->
<versions.plugin>1.3.1</versions.plugin>
<maven-compiler-plugin>3.1</maven-compiler-plugin>
<cobertura.plugin>2.5.1</cobertura.plugin> <!-- Reports Test Coverage -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<modules>
<module>services</module>
<module>presentation</module>
<module>service_validator</module>
<module>jsonvo</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>${javax.el-api.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- http://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/net.sourceforge.pmd/pmd -->
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>5.4.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<includeTests>true</includeTests>
<rulesets>
<ruleset>${checkstyle-config-url}</ruleset>
</rulesets>
<minimumTokens>100</minimumTokens>
<targetJdk>${java.version}</targetJdk>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.plugin.version}</version>
<configuration>
<targetJdk>${java.version}</targetJdk>
<minimumTokens>20</minimumTokens>
<skipEmptyReport>false</skipEmptyReport>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<!--<includeTests>true</includeTests>-->
<rulesets>
<ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset>
</rulesets>
<!--
<excludeRoots>
<excludeRoot>target/generated-sources/antlr</excludeRoot>
<excludeRoot>target/generated-sources/antlr/com/puppycrawl/tools/checkstyle/grammars/javadoc</excludeRoot>
</excludeRoots>
-->
</configuration>
<executions>
<execution>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
<goal>cpd-check</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs.plugin.version}</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<excludeFilterFile>config/findbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>
If you don't need to use your custom pmd rulesets you can omit the rulesets tag altogether.
If you want to use only some of pmd rulesets you can use predefined ones:
<rulesets>
<ruleset>/rulesets/java/braces.xml</ruleset>
<ruleset>/rulesets/java/naming.xml</ruleset>
</rulesets>
You are using version 3.6 of the maven-pmd-plugin. There is a default value for the rulesets - it's java-basic, java-imports and java-unusedcode. See the maven-pmd-plugin documentation.
If you want to start with these rulesets, you can omit the rulesets tag altogether, as krzyk mentioned.
Maven Plugin 3.6 uses PMD 5.3.5 - so downloading rulesets for PMD 4.3 will not work.
But, you don't need to download the rulesets. You can create your own custom ruleset, which references the rules you want to have checked in your code. And this would be your file pmd-rulesets.xml.
Is there any way to download/update through build or can we get all XML
files in one location anywhere?
There is no such a ruleset. Enabling all rules PMD provides, doesn't make sense, as some rules contradict each other. Please read "Best Practices": Choose the rules that are right for you.
Can you please let me know how to add my ruleset automatically whenever PMD
updated automatically?
You don't need to add your ruleset - you are using it already. However, if a new PMD version has new rules, you won't necessarily have these new rules activated. So, you might want to read the release notes of PMD and checkout if there are new interesting rules. Then you can reference the new rules in your ruleset file.
For the java language, you can see the available rules in the Rulesets index.
In maven pom file, my project packaging type is "jar" like bellow.
<packaging>jar</packaging>
My cargo-maven2-plugin configuration in pom.xml file from the legacy code. I try to run it Eclipse Kelpler, but since the plugin configuration didn't mention cargo-maven2-plugin version(I don't know actual version for this configuration), Eclipse try to get the most recent one which is 1.4.8. Based on the configuration, the Tomcat version looks like 6.0.14, but container id is 5x. Whole configuration seems doesn't right and I try to make it work. Any suggestions? The package type must jar and I can't change it.
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>${cargo.wait}</wait>
<container>
<containerId>tomcat5x</containerId>
<zipUrlInstaller>
<url>
http://archive.apache.org/dist/tomcat/tomcat-6/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.zip
</url>
<installDir>${installDir}</installDir>
</zipUrlInstaller>
</container>
<configuration>
<home>${project.build.directory}/tomcat5x/container</home>
<properties>
<cargo.hostname>${cargo.host}</cargo.hostname>
<cargo.servlet.port>${cargo.port}</cargo.servlet.port>
</properties>
<deployables>
<deployable>
<properties>
<context>ROOT</context>
</properties>
</deployable>
</deployables>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<cargo.host>localhost</cargo.host>
<cargo.port>25888</cargo.port>
<cargo.wait>false</cargo.wait>
<tomcat.version>6.0.14</tomcat.version>
</properties>
I set type for to "jar" to match project. But when I run maven build in Eclipse Kelper, I am getting following error message. As you can see there is no allowed type "jar" is listed. Could any one help?
org.codehaus.cargo.container.ContainerException: Cannot create deployable. There's no registered deployable for the parameters (container [id = [default]], deployable type [jar]). Valid types for this deployable are:
- ear
- war
- rar
- bundle
- file
- sar
- ejb
According to Cargo's Tomcat 5.x doc only war files can be deployed to tomcat, that's why it is failing. Why don't you use war to create a webapp? I don't know your requirements, but usually if you deploy on Tomcat you have a webapp in a war file. What do you need to do? Do you have a servlet or jsp file in your project? Do you need it to use it as a library for an other webapp?
You could create a web app and include the jar generated by that project as a dependency. Use org.apache.marmotta:marmotta-archetype-webapp Maven archetype to create your project and add your legacy project dependency to the pom, it would be something 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/maven v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test.war</groupId>
<artifactId>test-war</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>test-war Maven Webapp</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>
<build>
<finalName>test-war</finalName>
</build>
<dependencies>
<dependency>
<groupId>legacyProjectGroupId</groupId>
<artifactId>legacyProjectArtifactId</artifactId>
<version>legacyProjectVersion</version>
</dependency>
</dependencies>
</project>
I have Eclipse Indigo and M2E plugin installed.
So essentially I have a standard maven web project (let's call it proj-service) that is built into a war file in the package phase. This all works fine. My issue comes in when I have my other project (lets call it proj1) that needs to use classes from proj-service. I know that this is possible in maven+eclipse but it does not seem to be working at the moment. I have the following in proj1's pom right now:
<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.mycompany.foo</groupId>
<artifactId>proj1</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>proj1</name>
<properties>
<spring.version>3.1.0.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Maven Repo Libraries -->
.........
<!-- Interproject dependencies -->
<dependency>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj-service</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>lsoap</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Unfortunately with Maven's war packaging you can't reuse classes from war project, because there is no direct build artifact you can use for the class path.
So, in order to do share classes properly you need to extract those common classes into a 3rd common project (jar packaging) and make it as dependency in both of your other projects.
First you have to change the configuration of your proj-service project in the way to change the configuration of the maven-war-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<archiveClasses>true</archiveClasses>
...
</configuration>
</plugin>
This will it make possible to use the classes from the proj-service project in other projects via the following dependencies:
<dependency>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>myVersion</myVersion>
<classifier>classes</classifier>
</dependency>
This will result in changing your dependency from:
<dependency>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj-service</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
into:
<dependency>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj-service</artifactId>
<version>1.0</version>
<classifier>classes</classifier/>
</dependency>