Building non-java project - maven-2

I'm trying to build non-java project, it basically has some folders and subfolders I want to include in the jar is that possible ?

Sure. It's trivial if you use the standard layout (put your stuff inside src/main/resources), otherwise you just have to specify resource directories:
<build>
<resources>
<resource>
<directory>some/directory</directory>
<targetPath>first</targetPath>
</resource>
<resource>
<directory>some/other/directory</directory>
<targetPath>second</targetPath>
</resource>
<resource>
<directory>a/third/directory</directory>
<!-- standard target path -->
</resource>
</resources>
</build>
You should probably also set the property <maven.test.skip>true</maven.test.skip>. Nope, just checked, you don't need to.
Basically, some participants of the standard workflow (namely the compiler and the surefire plugin) check for java source folders, and if they don't find any, they just skip processing.

Related

Web Facets in Intellij web resource directory wrong

As you can see Intellij keeps suggesting the resource directory is src/main/webapp.
However, my resources configuration is
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
and
<sourceDirectory>src</sourceDirectory>
Yet, intellij will as in the picture keep suggesting src/main ... and from what ass is this webapp directory being pulled out of?
Very annoying. This thing has never worked with Intellij.
And you can't edit it either, because it will be overwritten as you need to configure it with maven.
I've even added:
<webappDirectory>assets</webappDirectory>
<webResources>
<webResource>assets</webResource>
</webResources>
but still the src/main/webapp directory is suggested.
In case of a Maven project IDE follows Maven rules. In Maven web resources are configured under <webResources> tag. Make sure you have something like this in pom.xml:
<webResources>
...
<resource>
<directory>web/resource/path></directory>
</resource>
...
</webResources>
For instance:
<warSourceDirectory>resources</warSourceDirectory>

Maven 2 Weblogic.xml replacement

I am having a problem about placing weblogic.xml under WEB-INF folder after mvn install. My weblogic.xml file is under src/main/resources/weblogic.xml and I want it to be placed under WEB-INF after install.(packaging is "war" by the way)
I tried this:
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>../resources</targetPath>
<excludes><exclude>web.xml</exclude><exclude>weblogic.xml</exclude></excludes>
</resource>
<resource>
<directory>src/main/resources/config</directory>
<targetPath>..</targetPath>
<includes><include>weblogic.xml</include></includes>
</resource>
</resources>
It is working with install but when I want a classpath using eclipse:eclipse, It gives the error :
Description Resource Path Location Type Cannot nest output folder 'ResponseManager/target/WEB-INF/resources' inside output folder
'ResponseManager/target/WEB-INF' ResponseManager Build path Build
Path Problem
because of this conf in classpath:
<classpathentry kind="src" path="src/main/resources" output="target/WEB-INF/resources" excluding="web.xml|weblogic.xml|**/*.java"/>
<classpathentry kind="src" path="src/main/resources/config" output="target/WEB-INF" including="weblogic.xml" excluding="**/*.java"/>
Any ideas?
Normally files under src/main/resources get packaged along the compiled class files, in a webapp they would be placed in WEB-INF/classes. Is there any reason why you can't put these under the standard path src/main/webapp?
If you need to package additional files which are not in the src/main/webapp folder then it would be better to configure these resources in the war plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<webResources>
<resource>
<directory>src/main/config</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>weblogic.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
It should be possible to specify the targetPath as above but I think it would be cleaner to reproduce the wanted directory structure inside your source folder.

Using maven using non standard directory layout

I am trying to apply maven to an existing project which already has a directory structure in place. All I can find from previous question is the following.
Maven directory structure
However, my requirement is more detailed. Please see below for the directory structure:
<root dir>
|
+--src-java
|
+--src-properties
|
+--WEB-INF
I know we could have something like
<build>
<sourceDirectory>src-java</sourceDirectory>
...
</build>
But sourceDirectory is for JAVA source code only, if I'm not mistaken.
For the above structure, how do I declare it in pom.xml? Moving the directory is my last option right now.
I guess you need to have something similar to below.
Seeing WEB-INF, I assume you want to build a war. Maven war plugin does this. You will need to configure this a bit since the folder structure is non-standard - for instance you may need to specify the location of web.xml using webXml property. These are documented in the usage page.
<build>
<sourceDirectory>src-java</sourceDirectory>
...
<resources>
<resource>
<directory>src-properties</directory>
</resource>
</resources>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>WEB-INF</warSourceDirectory>
...
</configuration>
</plugin>
</plugins>
</build>
You can change the default directory structure declared in the Super POM by overwriting them in your pom.
For your example, e.g.
<sourceDirectory>src-java</sourceDirectory>
<resources>
<resource>
<directory>src-properties</directory>
</resource>
</resources>
Maven will copy all resources to the jar file. If you want to include WEB-INF to the jar it would be best to move it into the specified resource directory. Otherwise you have to copy it by your own (with maven plugins) to the target directory - I suppose.
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
From here.

Exclude property files from resources

How to exclude files from src/main/resources, for ex : I have a folder named "map" in there, which I wanna keep and I want to delete everything from war(or not to package it inside at firstplace).
Or alternative but same result, exclude all *.resources files from src/main/resources and put in war everything else?
Thank you
You may configure your resources like this:
<build>
<resources>
<resource>
<directory>src/main/resources/map</directory>
</resource>
</resources>
</build>
or this:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.log</exclude>
</excludes>
</resource>
</resources>
</build>
For more details, click here.
If you don't want some resources to be copied into target/classes, you can define includes or excludes in the resource element as documented in Including and excluding files and directories. For example:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/map/*.*</exclude>
</excludes>
</resource>
</resources>
</build>
If you want resources to be still copied into target/classes but for some reason don't want them to be packaged in the final artifact, then configure the maven war plugin to use packagingExcludes.
The official documentation for the maven resources plugin describes how you can perform includes and excludes.
http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

How to add a file to a war with Maven

I have developed a maven plugin that downloads the release notes from JIRA.
It's bound by default to the 'generate-sources' phase and creates a 'release.txt' file in the build folder (${project.build.directory}).
My question: how can I add this file in the 'WEB-INF' folder of the war file built by Maven ?
I know I can use the 'maven-war-plugin' to include additional external resources from the 'src' folder, but I don't want my 'release.txt' file generated there (=not commitable to svn).
Thanks for your help. I wish you a nice day!
Maxence
I think this can be done using this feature of that plugin:
Adding and Filtering External Web Resources:
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
Which would allow you to generate your release.txt into a separate folder (not src) and have the plugin treat it as an extra resources folder.
Hope that helps.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}</directory>
<targetPath>WEB-INF</targetPath> <!-- introduced in plugin v 2.1 -->
<includes>
<include>release.txt</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>