I created an empty web project using Eclipse Mars and Maven 3.3.3. For now, this project only contains the 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.example.project</groupId>
<artifactId>web-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</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>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<build>
<plugins>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-war-plugin</artifactId> -->
<!-- <version>2.6</version> -->
<!-- <configuration> -->
<!-- <failOnMissingWebXml>false</failOnMissingWebXml> -->
<!-- </configuration> -->
<!-- </plugin> -->
</plugins>
</build>
</project>
Now Eclipse complains about a missing web.xml file. From the documentation of the maven-war-plugin one can set the user property failOnMissingWebXml, so there is no need to further configure this plugin. This works using Maven from the command line, the project is build successfully. But Eclipse still complains about the missing web.xml.
Does anybody know how to get rid of this Maven configuration error in Eclipse by just using this user property?
Update: I have another development environment using Eclipse Luna SR1 and Maven 3.2.5 where it does not complain about the missing web.xml in a newly created web project. So I wonder if this error is somehow suppressed by the m2e plugin.
Installing wtp-m2e 1.2.1 from http://download.eclipse.org/m2e-wtp/snapshots/mars/ fixes this issue for me.
Related
When I import the maven project into my ecliplse-luna I faced an error in the pom.xml
Plugin execution not covered by lifecycle configuration: org.apache.portals.pluto:maven-pluto-plugin:2.1.0-M3:assemble (execution: default, phase:
generate-resources)
so I have included <Pluginmanagement> tag in the pom.xml and it resolved the error. When I run mvn clean package/install, build was failed due to the below error (relative path \pluto-resources\web.xml is created by maven-pluto-plugin)
on project MyFirstPortlet: The specified web.xml file 'D:\PORTLET-SAMPLES\MyFirstPortlet\target\pluto-resources\web.xml' does not exist
I removed <Pluginmanagement> tag from the pom.xml and run the maven build now the maven build is successful.
The issue is, if <Pluginmanagement> tag present in the pom.xml eclipse project import doesnot throw any error but maven build is failed. if <Pluginmanagement> is not present then maven build is successful but eclipse project import is failed.
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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.helloworld</groupId>
<artifactId>MyFirstPortlet</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MyFirstPortlet Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.portals</groupId>
<artifactId>portlet-api_2.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- bind 'pluto2:assemble' goal to 'process-resources' lifecycle -->
<!-- This plugin will read your portlet.xml and web.xml and injects required
lines -->
<plugin>
<groupId>org.apache.portals.pluto</groupId>
<artifactId>maven-pluto-plugin</artifactId>
<version>2.1.0-M3</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- configure maven-war-plugin to use updated web.xml -->
<!-- This plugin will make sure your WAR will contain the updated web.xml -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>MyFirstPortlet</finalName>
</build>
</project>
Can any one advise me why adding pluginmanagement causes build failure and how to resolve plugin execution not covered by lifecycle error in eclipse with out the pluginmanagement tag.
I have to build a war file using maven to include jars conditionally,
each jar is created by a seperate maven project which deploys jar to nexus(our organisations remote) repository
Eg : I have jars like these core.jar,reward.jar,payment.jar,domains.jar so on
I need to build a final war based on conditions(environmnet) to include above jars
Combination of final war(w1)
w1.war : core.jar,domains.jar
w1.war : core.jar,domains.jar,rewards.jar(Any way to specify to include this jar if rewards is applicable)
The Maven WAR Plugin allows you to include/exclude JARs. For example:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<packagingExcludes>
WEB-INF/lib/excluded.jar
</packagingExcludes>
<packagingIncludes>
WEB-INF/lib/included.jar
</packagingIncludes>
</configuration>
</plugin>
You can associate the inclusions/exclusions with a condition by using profiles. For example, let the WAR plugin use properties (${excludedResources}, ${includedResources}) ...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<packagingExcludes>
${excludedResources}
</packagingExcludes>
<packagingIncludes>
${includedResources}
</packagingIncludes>
</configuration>
</plugin>
... and define values for those properties via profiles:
<profiles>
<profile>
<id>prod</id>
<properties>
<excludedResources>WEB-INF/lib/a.jar,WEB-INF/lib/b.jar</excludedResources>
<includedResources>WEB-INF/lib/c.jar</includedResources>
</properties>
</profile>
<profile>
<id>tst</id>
<properties>
<excludedResources>WEB-INF/lib/x.jar,WEB-INF/lib/y.jar</excludedResources>
<includedResources>WEB-INF/lib/z.jar</includedResources>
</properties>
</profile>
</profiles>
So, you can use the Maven WAR Plugin's built-in ability to tweak the WAR contents and you can make these tweaks conditional by using Maven profiles.
You can try to use profiles capabilities in maven. Each dependency can be included into its own profile block e.g. domains will be included only if you switch this profile on and services - by services profile.
At the same time you can identify common jars through the common dependency block (in our case core.jar will be common)
<?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.stackoverflow</groupId>
<artifactId>conditional-war</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>War Which Includes Jar By Conditions</name>
<!-- Common dependency block which will be always included -->
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<profiles>
<!-- Profile for domains jars. Will be included by
profile\condition "domains" -->
<profile>
<id>domains</id>
<activation>
<property>
<name>domains</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>domains</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
<!-- Profile for domains jars. Will be included by
profile\condition "services" -->
<profile>
<id>services</id>
<activation>
<property>
<name>services</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>services</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Command line for the activation can be following:
By this command line will be included core.jar and domains.jar
mvn clean install -Pdomains
In such case war will include core.jar and services.jar
mvn clean install -Pservices
And finally by this command line will be included all the jars
mvn clean install -Pdomains,services
I followed the instructions in Spring Boot Support in Spring Tool Suite 3.6.4 and ended up with an Eclipse project which has several issues. The number one issue is that when I right-click on the class containing the "main" entry method and select the "Run As" option, the only entry I get is the fallback "Run Configurations..." method. I neither get the option to run it as a "Spring Boot App" or as a "Java Application".
My question is how do I create the project or what do I do after it's created following the instructions in that site to get that Run As option?
In addition to the above information, I should add the following:
I'm using Eclipse 4.4.2 (Luna SR2) and STS 3.7.1
I've tried it on both Windows and Linux (Fedora with OpenJDK)
Used Java 8 (Sun Hotspot 64-bit 1.8.0_65)
When the pom.xml initially gets created, it has an error apparently due to a missing config the m2e wants for which I needed to add the following:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[3.1,)</versionRange>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
It doesn't look like the Eclise project is properly configured for a Java application either. There's no configuration for a Java src tree. Below is the .project file:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>demo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
I can manually run the app as per How to run Spring Boot web application in Eclipse itself? (by executing [Project] --> Run As --> Maven Build... --> Goal: spring-boot:run
To create a new spring-boot project in sts just click new spring-starter project, that will create the project for you.
New->Project->Spring->Spring starter project
You'll run throught the wizard select 'Web' checkbox to have the web app selected
this will create an application class like this
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
My auto generated 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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
You'll need to install the Spring Tool Suite plug-in for Eclipse. Then you'll see the "Spring Boot App" run configuration (and other STS features).
After creating a Spring Boot application via the Spring Starter project via the menu need to do additional steps: Go into project properties and enable the Java facet. Then, right-click project and Maven > Update Project.
I am using maven in my project & I've put database.properties file under
maven resources folder.
I am accessing it in spring application context
<context:property-placeholder location="classpath:database.properties" />
But I don't understand why I am getting this file not found error on server start.
Could not load properties; nested exception is
java.io.FileNotFoundException: class path resource
[database.properties] cannot be opened because it does not exist
To my knowledge whatever resource is put under resources folder it is added to the classpath automatically by maven.
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>myapp 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>myapp</finalName>
</build>
</project>
NOTE: Seems like there is some problem with the M2E plugin of eclipse luna. Executed the same code in Juno & it worked fine.
That's not enough to build a deployable war file with maven. You need at least the war plugin. There's a thorough tutorial here:
http://crunchify.com/how-to-create-a-war-file-from-eclipse-using-maven-plugin-apache-maven-war-plugin-usage/
Your pom will look something like below, and you'll need to run mvn clean install against that.
Also I see you have a spring app, where are the spring dependencies in 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CrunchifyTutorial</groupId>
<artifactId>CrunchifyTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</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>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
I'm having problems trying to get checkstyle to work properly in Hudson/Jenkins.
I created a custom checkstyle rule with very minimal rules in it (just to see if it works) and place it in some server:-
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="RegexpSingleline">
<property name="format" value="\s+$" />
<property name="minimum" value="0" />
<property name="maximum" value="0" />
<property name="message" value="Line has trailing spaces." />
</module>
</module>
I have a parent pom that 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>
<groupId>a.b</groupId>
<artifactId>c</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<configLocation>http://server/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
The actual project will include the parent pom, like this:-
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<groupId>a.b</groupId>
<artifactId>c</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>some</groupId>
<artifactId>project</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
...
</project>
When I execute mvn clean site from Eclipse, it works just fine. Instead of seeing 1000+ checkstyle errors using the default config/sun_checks.xml, I'm getting just 27 checkstyle errors.
When I run it in Jenkins, for some reason, it is not picking up my custom checkstyle rule. I'm getting 1000+ checkstyle errors from Jenkins. I checked the "Console Output" log and I'm not seeing any errors/warnings on checkstyle. The executed maven command from Jenkins look like this:-
<===[HUDSON REMOTING CAPACITY]===>channel started
Executing Maven: -B -f D:\hudson\jobs\test\workspace\pom.xml clean site
[INFO] Scanning for projects...
...
I'm hoping to be able to add -e or -X option to see a more robust log, but I can't find a place to insert them in Jenkins.
How do I get my custom checkstyle rule to work with Hudson/Jenkins?
Thanks much.
You can add the -eand -X switch in the "Goals und Optionen" field.
Are you refering checkstyle from an external location? If so, maybe you can try adding checkstyle to your project in your VCS (when this works it might be a network problem). Adding checkstyle.xml to your VCS also has the benefit, that you have reproducibility of your builds (and the other benifits VCS have to offer).
I setup how Maven finds my checkstyle.xml configLocation differently
maybe that'll get Jenkins working.
Also if you create a standard job instead of a maven job on Jenkins you can still execute a maven goal and you can simply add parameters
<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">
...
<properties>
<checkstyle.config.location>http://server/checkstyle.xml</checkstyle.config.location>
</properties>
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
</plugin>
</plugins>
</build>
</project>
Written up here:
http://blog.blundell-apps.com/create-your-own-checkstyle-check/
source code here:
https://github.com/blundell/CreateYourOwnCheckStyleCheck