Disable the default-jar execution
(...) So i will have 2 jar files (one created by assembly plugin and one created by maven jar which i dont want to be created).
Looks like you're doing pretty complicated things. Maybe Maven is not the right tool in your case.
How can I turn off the execution: default-jar.
You can set the <phase>
of the corresponding execution to something unknown, like none
:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
<!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
This seems to work as long as you're providing something else to be installed, like an assembly (I only tested install
). But of course, this is a hack.
Unable to disable generation of empty JAR (maven-jar-plugin)
I found the solution by myself, even if it's only a workaround. I delete the JAR using a delete antrun task if /src/main/java directory doesn't exist:
<!-- remove the empty JAR if not needed -->
<if>
<not><available file="${basedir}/src/main/java" type="dir" /></not>
<then>
<delete file="${project.build.directory}/${project.name}-${project.version}.jar"/>
</then>
</if>
this task requires antcontrib to work properly and, ofc, it doesn't work if you plan to do releases with maven (but it's ok for metadata-only components, like Talend Open Studio plugins)
How to avoid the generation of default jar when specifying a final name?
By changing the build section in the profile section from
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-tomcat-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
to
<build>
<finalName>${project.artifactId}-tomcat-${project.version}</finalName>
</build>
helped me to solve this issue
How do I avoid an empty test JAR in Maven?
skipIfEmpty
does the trick, kudos to wemu:
<plugin>
<!-- generate test-jar artifacts for creating test-test dependencies
across modules -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</execution>
</executions>
</plugin>
Documentation: https://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html#skipIfEmpty
Stop Maven from including dependencies in the built artifact (jar)
You can avoid packaging your dependencies inside your jar file by providing the scope they should be wrapped in. But since I looked to your pom.xml descriptor and find nothing misconfigured, I will suggest to use the maven-jar-plugin
to exclude all third party libraries as follows:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<excludes>
<exclude>*.jar</exclude>
</excludes>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
Hope this helps.
BR.
External JARs are not present in WAR
As khmarbaise said, solution to my problem was adding my dependencies to my local Maven repository instead of using system scope and system path properties.
Guide for adding 3rd party JARs to your local Maven repository: https://mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/
Related Topics
What Is the Point of Getters and Setters
How to Merge Documents Correctly
Dynamically Find the Class That Represents a Primitive Java Type
Is Concurrenthashmap Totally Safe
Accessing Post Variables Using Java Servlets
Maximum Size of Hashset, Vector, Linkedlist
Java: String Concat VS Stringbuilder - Optimised, So What Should I Do
How Do Format a Phone Number as a String in Java
Java- the Meaning of <T Extends Comparable<T>>
Why Is Each Public Class in a Separate File
Pdfbox - Signature Validity Checkmark Not Visible in Acrobat Reader
Intellij - Convert a Java Project/Module into a Maven Project/Module
Java 8 Streams - Collect VS Reduce
Waiting on Multiple Threads to Complete in Java