Display maven-excluded directories in STS package explorer? - eclipse

I use tags in my maven POM file to exclude a directory structure I do not want compiled:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<excludes>
<exclude>**/somedir/**</exclude>
</excludes>
</configuration>
</plugin>
However, I would like to have the directory displayed in the STS (3.9.2) Package Explorer. I've tried disabling all view filters, but the excluded directory doesn't display. Is it possible to have maven-excluded directories displayed?
The project itself was created using "Import existing Maven project."

Related

How to use build-helper-maven-plugin to create extra directory?

I have a Java Maven project with the following structure. (This is a logical structure, not necessarily the exact directory structure.)
Project
|-Submodule
| |-src/main/java
| |-src/main/resources
| |-src/test/java
| |-src/test/resources
| `-pom.xml
`-pom.xml
In accordance with (my understanding of) Maven standards, the parent pom references the submodule in it's <modules> tag, and the submodule pom references the parent pom as it's <parent>.
Now, my goal is to use Maven to add two new source folders to the submodule, namely src/integrationTest/java and src/integrationTest/resources. I want Maven to "know about" these two folders so that I can execute the tests therein using my Maven testing plugin, maven-pmd-plugin. And I want Eclipse to "know about" these two folders so that they display correctly in Eclipse's graphical Project Explorer.
I was told that the build-helper-maven-plugin plugin could be used to create these additional directories that I needed. So I added the following configuration to my submodule pom:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integration-test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
When I rebuilt the project, Maven didn't generate the directories I wanted. So I took the plugin configuration out of my submodule pom and put it in my parent pom instead. Maven still didn't generate my directories.
At this point, I don't know how to get this plugin working. I'm trying to follow other online tutorials, but I must be doing something wrong. Could anyone explain which pom file is intended to configure build-helper-maven-plugin? And how do I configure Eclipse to display the new Maven project structure correctly?
Thanks for the help!
khmarbaise's comment made me realize my mistake, although I didn't take his advice.
The build-helper-maven-plugin configuration should go in the submodule pom (not the parent pom) where I originally had it. But Maven will not create these directories for you, you create the directories and then Maven uses them.
Once Maven is using your new directories, Eclipse displays them just fine.

target classes getting modified after import maven project

git status shows
modified: target/classes/com/abcplusd/util/JSONUtil$1.class
after clone and import maven project from github repository.
part of Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>target/maven-status/maven-compiler-plugin/*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.springframework.build</groupId>
<artifactId>aws-maven</artifactId>
<version>5.0.0.RELEASE</version>
</extension>
</extensions>
</build>
Your problem is that your target folder is located under the folder containing your .git repository. Hence, it appears that Git is viewing changed files from the build process as being something which should be versioned (they should not).
The general solution to this is to change your build target folder to something outside the path which Git manages.

Maven keeps changing project settings - How to edit effective pom file?

I told Eclipse to use the output folder
E:\java\<project>\<project>-parent\<project>-web-server\war\WEB-INF\classes
but every Maven update changes it back to the value as stored in the effective pom:
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>E:\java\<project>\<project>-parent\<project>-web-server\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<!-- .... -->
</plugin>
The file is not editable and I don't really know how this file gets generated and/or how to change it. How can I manipulate the values in the effective pom file?
Edit:
Another thing you've already noticed are those absolute paths I'd like to get rid of. So as a side-quest: How would I do that?
You have to modify your maven configuration to use the desired output folder.
The effective pom you see is the "calculated" pom and hence not editable. You can edit the pom file by clicking on the pom.xml tab (just next to the effective pom tab)
Edit the pom file and add the folders there. The effective POM file is, as you said, autogenerated on each build, thus also the absolute paths. In the pom file itself you of course have no absolute paths.
To change the output folder to the folder "war" in your project, add the following to your pom.xml:
<build>
<outputDirectory>${project.basedir}/war</outputDirectory>
</build>
You can see all configuration properties in the Maven manual: https://maven.apache.org/pom.html

Maven: exclude resource from war

I am currently trying to exclude some resource from my built war.
I have read the documentation and the forums, and found a lot of informations.
Unfortunately nothing worked in my case...
I have an Eclipse Maven project, and if I'm right, maven-war-plugin is the default "war builder", so I have to override it in my pom.xml in order to exclude the resource from the buildt war.
I tried warSourceExcludes, packagingExcludes and webResources/excludes :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceExcludes>src/main/webapp/frontEndWorkspace</warSourceExcludes>
<packagingExcludes>src/main/webapp/frontEndWorkspace
</packagingExcludes>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp</directory>
<!-- the list has a default value of ** -->
<excludes>
<exclude>**/frontEndWorkspace</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
Despite this configuration, I still have the frontEndWorkspace directory pushed in my Tomcat...
I wonder if it comes from the fact that I use it in my Eclipse environment?
Thanks in advance!
The parameters that you can use are packagingExcludes which is more generic (applies on the complete war structure) or warSourceExcludes if the files you want to exclude are specifically in the folder defined by the parameter warSourceDirectory (default being ${basedir}/src/main/webapp) (see here). It works easily when you know that it starts considering the folder structure of the war.
Example :
This will exclude all the files finishing by *.jsp contained in the folder WEB-INF of the folder defined by the parameter warSourceDirectory (default being ${basedir}/src/main/webapp) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceExcludes>WEB-INF/**/*.jsp</warSourceExcludes>
</configuration>
</plugin>
This will exclude all the files contained in all the folders pouet contained in the war (but not the folder structure) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>**/pouet/**/*.*</packagingExcludes>
</configuration>
</plugin>
The problem of your configuration <warSourceExcludes>src/main/webapp/frontEndWorkspace</warSourceExcludes> is that you start from the source folder which is wrong. You just have to remove src/main/webapp and add /** after frontEndWorkspace to have <warSourceExcludes>/frontEndWorkspace/**</warSourceExcludes> working (or <warSourceExcludes>frontEndWorkspace/**</warSourceExcludes>).
I am finding the same issue within Intellij IDEA which is using Maven 3.
The war file it generates contains the directory I am excluding.
UPD
Solution is to use syntax as below to eliminate the myFolder directory
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/resources</directory>
<excludes>
<exclude>**/myFolder/**</exclude>
</excludes>
</resource>
</webResources>

How to debug an OSGi Bundle inside eclipse using maven structured project

I have a maven project which library should also be an OSGi bundle with an
declarative service. I added the OSGI-INF folder with the service.xml inside
src/java/resources which will be added to the jar. But: When I start the project as equinox project, where I want to check if the service is loaded, I get the error that the OSGI-INF/service.xml can't be found. I guess eclipse won't add the resources folder to the classpath when starting.
BTW: The MANIFEST-MF is in the root folder and the pom.xml contains the following text:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
Has anbody a good idea how to tell eclipse where to find the metadata files? I'm using m2eclipse if this is relevant.
Thanks in advance
Hannes
I've the same issues but I've manually tweaked my POM.xml for copying the generate target/classes/META-INF/** stuff (MANIFEST.MF, property files, spring XMLs, ...) into the project ROOT folder (which Eclipse PDE expects):
<!--
We copy all stuff from target/classes/META-INF into META-INF/ in order
to keep Maven output with PDE.
-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>synch-pde-metadata-from-maven</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/META-INF</outputDirectory>
<resources>
<resource>
<directory>target/classes/META-INF</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!--
We delete all stuff from the root bundle's META-INF
-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>META-INF</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
(I also clean up things when mvn clean is called) It is not really efficient but it works.
Ps: you may have to right-click on the project and make it a plug-in project in order for this to work.
The Problem is that Eclipse needs that OSGI-INF (and also META-INF) Folder in root.
I have found a link on how to probably solve the problem.
https://www.nuxeo.com/blog/working-with-osgi-and-maven-in-eclipse/
Basically they put the OSGI-INF and META-INF Folders into src/main/resources
Then they set the src/main/resources Folder as root of the OSGI project. So that Eclipse has both Folders at root.
To have Soure Files also available they added a Linked Resources to src/main/java by adding an entry to the .project File
<linkedResources>
<link>
<name>src</name>
<type>2</type>
<locationURI>PARENT-1-PROJECT_LOC/java</locationURI>
</link>
</linkedResources>
Now you just need to copy the .prject and .classpath Files into src/main/resources (your new root) and everything should be working.
By the time of this writing i didn't test this on my own but will do so in the near future.