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

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.

Related

Maven sure-fire-report name change not working

I am using Maven Sure fire plugin to generate report for my selenium TESTNG test suites.
After the test, it generates the output in the location ..\target\local\surefire-reports.
The name of the report is emailable-report.html.
I saw that we can chnage the name of the report by passing in Pom.xml.
Below in the section in pom.xml.
But I don't see the name changed after the report is generated. Am I missing something or are there any other way to change the name of 'emailable-report.html'
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<configuration>
<outputName>desired_name</outputName>
</configuration>
</plugin>
</plugins>
</reporting>
If you only use maven-surefire-report-plugin in your POM, then yes, the outputName parameter is ignored.
If you also add maven-site-plugin to your list of build plug-ins, then you will see the effect of using the outputName parameter.
So, for example:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M2</version>
<configuration>
<locales>en</locales>
</configuration>
</plugin>
</plugins>
</build>
...
<reporting>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<outputName>emailable-report</outputName>
</configuration>
</plugin>
</plugins>
</reporting>
When you do this, you will still continue to see a file called surefire-report.html being created - but now you will also see emailable-report.html as a separate file.
Both these files are in your project's /target/site/ directory.
They contain the same reporting statistics.
There is one difference between the 2 files: The emailable-report.html file is part of the Maven project web site - and therefore it contains navigation links similar to those shown in this official example.
Which links you see depends on how you have configured your Maven project web site.
In my case, it only shows links to the SureFire report and the JavaDocs.
But you may prefer to stick with the original surefire-report.html file, because of this, and just rename it to whatever you want.

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

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>

Installing and compiling Maven artifacts on Java 8

I have a project with a pom.xml that has the following <build> declaration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
When I run mvn install on this project, it compiles the project, runs unit tests and publishes it to my local repo. I am trying to learn a little more about Maven here, and am having a tough time finding documentation/explanations on the following:
How am I able to run mvn install, if the POM doesn't declare it under build/plugins? Does maven-compiler-plugin include maven-install-plugin, if so, how could I have figured that out?
Most importantly: the value of build/plugins/plugin/configuration/source and .../target are both set to 1.8. If my machine has Java 8 on it, and I run mvn install on this project without any errors, does that guarantee that the project builds with Java 8? I'm looking at the docs for the Compiler Plugin and don't see those source/target configs listed anywhere.
First you should learn what the build life cycle is and how it works and how the plugins are bound to the life cycle by default.
Furthermore you should understand that in Maven every project inherits from the super pom file which is part of the maven distribution (the package you have downloaded). The super pom defines the default folder layout and some versions of plugins.
The question to define the maven-compiler-plugin as you did is to be very accurate simply wrong. You should have defined it like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This would overwrite the definition which is inherited by the super pom and changes it's configuration. In your case i would suggest to change the definition into this:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
..
</project>
The encoding should be set globally cause there are other plugins which use this definition like the maven-resources-plugin. The usage of the above property simplifies this, cause every plugin which has an option for encoding will use the default as defined in the property.
To be sure using the correct version of Java (your JDK on your machine) you have to use the maven-enforcer-plugin.
Apart from that please take a look onto the plugins page which shows the most up-to-date releases of the plugins.
As a good documentation i can recomment the Books on Maven but be aware they are written with Maven 2 in mind. So if something is not clear ask on users mailing list of here on SO.

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

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