Including a Maven product from different directory into project directoy - maven

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>

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>

mvn war:war without copying resources

I have a file in a Maven project that need to be obsfuscated. At the moment I:
Clean/build the project;
Open an eternal application to obsfuscate the file in the /target/ROOT/blah folder;
I then want to run mvn war:war but it always copies the resources folder back into the /target/ROOT folder which overwrites the obsfuscated file.
MVN output
Packaging webapp
Assembling webapp [core] in [core\target\ROOT]
Processing war project
Copying webapp resources [src\main\webapp] <= I THINK THIS IS THE PROBLEM
Webapp assembled in [22812 msecs]
Building war: target\ROOT.war
I have tried the following and a few variations:
<profile>
<id>war-only</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceExcludes>**</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Any suggestions please?
OK got it eventually:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>${basedir}/src/main/null</warSourceDirectory>
</configuration>
</plugin>
Setting warSourceDirectory to any non-existant directory meant it didn't copy anything in.

Excluding JAR Files From the EAR using maven

My EAR includes 8 JAR files which are in the root of my EAR. I want to delete two of them for my final deployment EAR package.
I was trying do this as it is described here:
https://maven.apache.org/plugins/maven-ear-plugin/examples/excluding-files-from-ear.html
But seem not to work.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>test1.jar,test2.jar</packagingExcludes>
</configuration>
...
</plugin>

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.

Resources