<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/Application.java</exclude>
</excludes>
</configuration>
</plugin>
this is my pom.xml , maven-compiler-plugin.version is 3.8.1 .
but i see the Applciation.class still in my jar package by maven
You are looking at the wrong location. From what I see in the screenshot, you've found some Application file from the External Libraries. What the maven-compiler-plugin does is to generate the target folder. That's where the class file should be excluded from. Check the existence of the file class under:
target/classes/...
And don't forget to run mvn clean install before (with emphasis on clean - this will wipe out your target folder)
In a project, I had to do a similar thing, due I need to exclude the module-info.java. I resolved using this configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<exclude>**/module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
If you want the entire project you can get it from GitHub. I hope this helps.
Related
I would like to set up the maven java-docs plugin in my project to create an aggregated report that includes only some classes from some of the modules and output the report to a folder of choice.
I have already tried to work with the Maven documentation here however whats indicated there does not seem to work for me.
I have tried the following configuration in the past and ran it as:
mvn javadoc:javadoc, or even javadoc:aggregate with the following parent/child pom configurations:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<inherited>false</inherited>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>package</phase>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
I have used something like this in the past:
parent pom.xml
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</pluginManagement>
...
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>site</phase>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</build>
Desired child module pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>false</skip>
<noqualifier>all</noqualifier>
<sourceFileIncludes>
<include>**\/\Class1.java</include>
<include>**\/\Class2.java</include>
<include>**\/\Interface3.java</include>
<include>**\/\Class4.java</include>
</sourceFileIncludes>
<reportOutputDirectory>${project.parent.basedir}/..</reportOutputDirectory>
<destDir>java-docs</destDir>
</configuration>
</plugin>
</plugins>
</build>
This configuration works fine if I am only generating from one single module, however once another child module is picked and configured as the one shown before, running mvn javadoc:aggregate continues to generate the docs for module 1 only, and module 2 gets ignored(or maybe even overriden)
Has anyone worked with a similar scenario, a multi module project structured like so:
ParentFolder
. . . module1
pom.xml
. . . module3
pom.xml
. . . module4
pom.xml
pom.xml
and have succeeded generating an aggregated java docs report using the maven java docs plugin, while excluding some classes and outputting the results to a folder of their choice?
Any help with this would be greatly appreciated!
Do you have one parent POM that contains both plugin config for the child POMs, and module definitions? If so, you may want to consider separating this POM into a separate aggregator (module definitions) and parent (anything else in the current POM that should be shared with children).
This answer goes into a lot more detail about Maven build order and why the behavior occurs.
The aggregator POM will also hold the configuration for child module data that should be aggregated, such as Javadoc.
I'm new to maven and currently try to assemble a scala project with it. Project structure:
dir
|
|--src/main/java
|
|--src/main/scala
|
|--pom.xml
I was kind of surprised that classes compiled from *.java end up in jar, but one compiled from *.scala do not. I added these plugins to pom.xml
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.3</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
I though maven-jar-plugin is responsible for assembling jar files. But for some reason, it does not add scala-compiled classes.
QUESTION: Who adds .class file into a final jar after executing mvn install? How to add .class-files compiled with scala compiler?
mvn package will build your jar, however maven-compiler-plugin will only compile your java source files not your scala source files. Scala-maven-plugin can be used to compile both java and scala sources.
I wrote a blog post on this a while ago, that may help http://blog.rizvn.com/2016/04/scala-and-maven.html
You will need to tell maven about src/main/scala, since you are putting your scala code under src/main/java. This is done through the build section like so:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
...
</build>
Can you try something like this, using "scala-maven-plugin" instead. Then execute maven goal : mvn clean package
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src/test/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala-maven-plugin.version}</version>
<configuration>
<sourceDir>${basedir}/src</sourceDir>
<outputDir>${basedir}/target/classes</outputDir>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I have a problem with CTW aspects using aspectj-maven-plugin. I get the following error (execution entry is being highlighted):
Multiple annotations found at this line:
- Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.5:compile failed: Plugin
org.codehaus.mojo:aspectj-maven-plugin:1.5 or one of its dependencies could not be resolved: Could not find artifact
com.sun:tools:jar:1.7.0_21 at specified path C:\Program Files\Java\jre7/../lib/tools.jar (org.codehaus.mojo:aspectj-maven-
plugin:1.5:compile:default:compile)
- Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.5:test-compile failed: Plugin
org.codehaus.mojo:aspectj-maven-plugin:1.5 or one of its dependencies could not be resolved: Could not find artifact
com.sun:tools:jar:1.7.0_21 at specified path C:\Program Files\Java\jre7/../lib/tools.jar (org.codehaus.mojo:aspectj-maven-
plugin:1.5:test-compile:default:test-compile)
On the configuration:
<build>
<plugins>
<!-- http://mojo.codehaus.org/aspectj-maven-plugin/usage.html -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
<source>1.7</source>
<target>1.7</target>
<sources>
<source>
<basedir>src/main/java</basedir>
<includes>
<include>**/*Aspect.java</include>
</includes>
</source>
</sources>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
What am I doing wrong? It looks like as if this plugin was unable to find jdk? But why?
Is your JAVA_HOME set properly? Please check that. It worked perfectly for me. So I think you should add below mentioned plugin and try:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Run mvn compile after that.
Please check the JAVA_HOME env variable. This happened to me when JAVA_HOME is pointed to JRE folder rather than jdk folder.
I had this problem running with java 11, seems like it is only compatible with java 8.
Looking into the project, aspectj-maven-plugin it looks like the update was committed but never actually merged.
I have CSS and JavaScript files in src/main/webapp directory of my project.
I want to join add joined and minified version of these resources to my WAR file and to the place where tomcat-maven-plugin picks it up.
I used yuicompressor-maven-plugin to create the files and put it to ${project.build.directory}/${project.build.finalName}. It works great for maven package and those resources make their way to WAR file, but somehow tomcat-maven-plugin does not see those at all. Should I use a different directory for it?
My pom:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<path>/MyApp</path>
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
</configuration>
</plugin>
<plugin>
<version>2.5.1</version>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>context.xml</include>
</includes>
</resource>
</webResources>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<excludes>
<exclude>**/*</exclude>
</excludes>
<aggregations>
<aggregation>
<output>${project.build.directory}/${project.build.finalName}/js/commons-pack.js</output>
<includes>
<include>${project.build.sourceDirectory}/../webapp/js1.js</include>
<include>${project.build.sourceDirectory}/../webapp/js2.js</include>
...
What should I do to make mvn tomcat:run to also pick up my generated files?
Use warSourceDirectory:
<warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
Instead of this configuration property (warDirectory) for the tomcat-maven-plugin:
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
According to the tomcat-maven-plugin documentation, warSourceDirectory is where the web resources get picked up, and its default value is ${basedir}/src/main/webapp. This means that if you don’t set that property, you need to generate your unified/minified JavaScript file under ${basedir}/src/main/webapp.
If you set warSourceDirectory to the output folder, this means you need to generate this file before starting Tomcat.
Alternatively, you can also use the run-war goal instead of run, e.g. mvn tomcat6:run-war. This wil use the exploded war in your build directory (and thus filtered resources). See this site. There is also run-war-only which skips the packaging phase.
Note the plugin is now maintained at Apache (so upgrade a bit :-) ) see http://tomcat.apache.org/maven-plugin-2.0/.
Even it works using install I'm not sure it's the optimum solution (regarding io and build time).
The tomcat run must be able to use resources from more than one directory (I'm not sure it's possible with the current tomcat embeded api).
Can you add a feature request here https://issues.apache.org/jira/browse/MTOMCAT
Thanks
I have multimodule project
Proj
+ModuleA
src
main
java
overview.html
pom.xml
+ModuleB
pom.xml
pom.xml
I'm trying to generate javadoc for these module. I want to add overview.html in overviewsummary.html. I've place overview.html under moduleA/src/main but it's not updating the overview summary page.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<stylesheetfile>javadoc.css</stylesheetfile>
<overview>${basedir}\moduleA\src\main\overview.html</overview>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<show>private</show>
</configuration>
</execution>
</executions>
</plugin>
I looked at the documentation http://docs.oracle.com/javase/6/docs/tooldocs/windows/javadoc.html#overview, everything looks fine to me. Is there anything wrong with my path ?
I could solve this problem by using below configuration
<overview>${project.build.sourceDirectory}/overview.html</overview>
We will have to use ${project.build.sourceDirectory}, ${basedir} doesn't seem to be working. Place the overview.html under /src/main/java directory.
In case of multi module project also, place the overview.html under any of the module's source directory (i.e src/main/java).