How to place output Jar and War files in another specified folder(it may be outside of the project)? - maven

i want to place output jar or war in another separate folder which should contain only jar or war file. i.e folder may be outside of the project. is that possible?

Although generally it's not a good idea to deviate from Maven conventions, you can use outputDirectory parameter in maven-jar-plugin to specify a directory other than ${project.build.directory}
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<outputDirectory>path/to/your/folder</outputDirectory>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>

Related

Including a Maven product from different directory into project directoy

My question I have a project in x directory and another maven project in x/y directory. Now how can I get the jar files be generated for a project in x directory from a project in y directory
You can use the jar-plugin within a project's pom.xml to modify the location of the output jar -
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<outputDirectory>/x/y</outputDirectory> <!-- specify the relative desired path here -->
</configuration>
</plugin>
</plugins>
</build>

I don't want to include external jar in my maven war

I don't want to include external jars when I build a war.What should I do?
Though not sure about why are you thinking to exclude the jar files, but yes you can do that if you are using maven-war-plugin
This will work out
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
This a whole bunch of configuration plugin that excludes all .jar files.
This source explains about that and even regex patterns that can be used.

How to include uncompiled java files in a JAR built by Tycho?

I have a source root with *.java files, but I don't want them to be compiled. Instead, the *.java files should be copied into the jar as they are. The use case for this is that the *.java files are templates and hence should be preserved as they are.
To achieve this, I tried to exclude a source folder from compiling phase of my build and I am quite confused by the official documentation to the Tycho OSGi Compiler Plugin. It says I can use parameter excludeResources but I don't really know how to handle all these parameter types. pom.xml is a structured text file and not a source file, that's why I don't understand how to use java.util.Set for that parameter.
My POM goes like this:
...
<build>
<plugins>
...
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>0.21.0</extensions>
<configuration>
<excludeResources>
<!-- Set of folders consisting of a source folder named "res"
which should be excluded completely from compilation -->
</excludeResources>
</configuration>
</plugin>
</plugins>
</build>
Is it a right approach? If yes, how would I complete the configuration?
Try something like this to remove any occurences of "res" folder and files:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<excludeResources>
<excludeResource>**/res</excludeResource>
</excludeResources>
</configuration>
</plugin>
or this, alternatively, for example, to include the "res" folder and exclude .jar files:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includes>
<include>res</include>
</includes>
<excludes>
<exclude>**/*.jar</exclude>
</excludes>
</configuration>
</plugin>
Or, to exclude everything that is not the "res" folder:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<excludeResources>
<excludeResource>!**/res</excludeResource>
</excludeResources>
</configuration>
</plugin>
If you want to exclude a whole source root folder from compilation, simply do not add it to any of the src.* entries in build.properties, see [1]
If on the other hand you want to include the *.java files in the source root folder in the resulting jar, add the root folder to the list of bin.includes in build.properties.
excludeResources is unrelated to your problem, as the docs you linked say:
"A list of exclusion filters for non-java resource files which should not be copied to the output directory."
[1] http://eclipse.org/tycho/sitedocs/BuildProperties.html

Why would a maven-war-plugin generate a JAR instead of a WAR?

I am following this Contract first using CXF tutorial and while the resulting pom.xml generates sources and even completes build successfully, it fails to create a WAR file.
Instead, it creates a JAR file.
My understanding is that the part in the pom.xml that's responsible for creating the WAR is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>D:/path/to/profile/autodeploy</outputDirectory>
</configuration>
</plugin>
I don't see any <goal> or <execution> element there (unlike in the build-helper-maven-plugin one), but I also understand that with this plugin this is implied as even the official usage page demonstrates:
<project>
...
<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>
...
</project>
So... what am I missing?
What could possibly explain a maven-war-plugin that behaves in unexpected way like this and produces a JAR instead of a WAR by default?
Is there a way to force it to produce a WAR?
packaging should be as below.
<packaging>war</packaging>
if it won't help then try binding your plug-in configuration with a lifecycle phase.
in your project definition , please check if packaging is missing or not , it should be some thing like this .
<groupId>some.groupid</groupId>
<artifactId>My Web Application</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<description>My First Web Application</description>
By default maven war plugin binds to package phase of the lifecycle ,so its important that we should mention the type of packaging we want once the build is done.
I would like to suggest to have a look at the Maven specs for war plugin.

How to add libs to Classpath in my manifest file via maven?

I using Maven 3 + hudson + artifacotory
I used the following
<artifactId>maven-war-plugin</artifactId> <addClasspath>true</addClasspath> <classpathPrefix>WEB-INF/lib/</classpathPrefix> </manifest>
and I got the result as.....
WEB-INF/lib/gwt-servlet-2.4.0.jar WEB-INF/lib/gwt-user-2.4
.0.jar WEB-INF/lib/validation-api-1.0.0.GA.jar WEB-INF/lib/validation
-api-1.0.0.GA-sources.jar WEB-INF/lib/log4j-1.2.16.jar WEB-INF/lib/co
mmons-lang-2.6.jar
I am find well and good.
My one more requirement is,
I need to add/append two more libs with the above manifest file. see below
/u01/app/TimesTen/tt1121/lib/orai18n.jar /u01/app/TimesTen/tt1121/lib/ttjdbc5.jar
So how can add/append this is to my Manifest, so that above 3 will be included?
maven war plugin as well as maven jar plugin use maven archiver which in turn allows you to specify your own manifest file. According to the documentation,
The content of your own manifest file will be merged with the entries
generated by Maven Archiver.
Cut/pasting the relevant pom snippet from the above link for ready reference
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
...
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
So you could add the additional entries in this custom MANIFEST.MF and use it in conjunction with the maven war plugin.

Resources