Netbeans reloads no class when "Apply Code Changes" in a maven project with remote jpda debugging - maven

So I have a maven project which produces a jar package containing some ant tasks.
When I run my ant build script somewhere else with jpda open, and debug the tasks, say MyTask with NetBeans, the Apple Code Changes button doesn't work. Here is the output of the netbeans console:
cd /trunks/tasks; JAVA_HOME=/opt/jdk /opt/netbeans-7.0/java/maven/bin/mvn -Djpda.stopclass=com.abc.ant.MyTask compile
Scanning for projects...
------------------------------------------------------------------------
Building tasks 1.0-SNAPSHOT
------------------------------------------------------------------------
[resources:resources]
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource to com/abc/ant
[compiler:compile]
Compiling 1 source file to /trunks/tasks/build/classes
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1.548s
Finished at: Fri Mar 09 17:45:24 CST 2012
Final Memory: 11M/149M
------------------------------------------------------------------------
NetBeans: classes to reload: []
NetBeans: No class to reload
So Netbeans does successfully tell Maven what class needs to be compiled. However, NetBeans won't reload the compiled class. Is it because my ant process is using the jar package produced by the Maven project, or because of other reasons?
Note: I have some custom configurations, like where to output the compiled classes, and where to put the jar package. Could that be a reason?
Update 2:
OK I found the reason by myself.
It's because I added the following line under <build> in the pom.xml:
<directory>${my.custom.work.dir}/build</directory>
So maven will output the compiled class files to this directory, rather than the default ${basedir}/target. However, Netbeans seems to be too stupid to recognize that -- it just tries the default directory.
Now the question could be much easier: is there any way to make the IDE recognize that by adding configuration in the pom?

In [your_home_path]/.netbeans/7.0/maven/conf you will find a setting.xml file.
Here you can set ${my.custom.work.dir} in <profiles> tag
You can find examples here (in section Properties)
Edit :
It works for me with this kind of POM (in Netbeans 7.0.1) :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<directory>${my.custom.work.dir}/build</directory>
</build>
<properties>
<my.custom.work.dir>/home/alain/Bureau</my.custom.work.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Related

Spring Cloud Contract not deploying to Artifactory in Maven multi module projects

I have a multi module project in which each module deploys fine to Artifactory until I add spring-cloud-contract-maven-plugin to one of the modules (the service, as it is a producer API).
The project has this structure:
parent
- common (shared DTOs)
- client
- service
We want to remove the client and the common in the future and have Feign clients in the consumers for reducing the coupling, and have a basic project without inner modules, but for now we have to keep this structure.
I first noticed that the stubs were not pushed to Artifactory, so my initial workaround was to add this to the Jenkins pipeline
sh './mvnw clean deploy -U --projects=xxx-service'
It deploys the service and the stubs, but I noticed that none of the modules gets deployed when this command is executed:
sh './mvnw clean deploy -U'
This is the end of the output:
[INFO] Installing /xxx/xxx-service/target/xxx-service-1.7.0-SNAPSHOT.jar to /xxx/.m2/repository/xxx/xxx-service/1.7.0-SNAPSHOT/xxx-service-1.7.0-SNAPSHOT.jar
[INFO] Installing /xxx/xxx-service/pom.xml to /xxx/.m2/repository/xxx/xxx-service/1.7.0-SNAPSHOT/xxx-service-1.7.0-SNAPSHOT.pom
[INFO] Installing /xxx/xxx-service/target/xxx-service-1.7.0-SNAPSHOT-stubs.jar to /xxx/.m2/repository/xxx/xxx-service/1.7.0-SNAPSHOT/xxx-service-1.7.0-SNAPSHOT-stubs.jar
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) # xxx-service ---
[INFO] Deploying xxx:xxx-service:1.7.0-SNAPSHOT at end
I have tried to move all the Maven configuration to the parent POM file and keep the contracts and the base test classes in the service module. I have looked to this page that explains how to configure the plugin and I have seen that I can use contractsDirectory to specify the directory of the contract files, gmavenplus-plugin to specify the directory of the generated tests and packageWithBaseClasses to specify the package of the base classes. However I don't see any way to specify the directory of the base classes. I cannot move the base test classes to the parent because they use some classes of the service module for generating the mocks.
Is there any way of doing it or I have to create a separate project for the contracts?
Thanks in advance
Cause of the problem:
I had this in a parent project extended by my API:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<configuration>
<deployAtEnd>true</deployAtEnd>
</configuration>
</plugin>
Why is this a problem:
maven-deploy-plugin seems to conflict with multi module projects with plugins that use extensions like spring-cloud-contract-maven-plugin. There is a known issue documented here, look to the answer of Jerome that is also here.
Solution 1:
Remove the deployAtEnd option from the previous block so it would be:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
</plugin>
Solution 2:
Configure the plugin in all the modules although they don't need it. For doing so:
Add an empty "contracts" folder under src/test/resources on all the modules
Add this to the pom file of the service module:
<build>
<plugins>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration
<baseClassForTests>com.xxx.BaseContractTest</baseClassForTests>
</configuration>
</plugin>
</plugins>
</build>
Add this to the pom file of the other modules:
<build>
<plugins>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

Maven Install plugin: parameter file is missing or invalid

I have a local jar and I want to use it in my project. There are plenty ways to do it: just install manually into local repo, do it with script in parent pom, use system scope, use local repo declaration.
I decided to use Maven Install plugin to install jar into the repo. Here is a configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>jacob</groupId>
<artifactId>jacob</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${basedir}\lib\jacob.jar</file>
</configuration>
</execution>
</executions>
</plugin>
I tried to run it in many ways:
mvn initialize install:install-file
mvn initialize
mvn install:install-file
But all the time I have an exception:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file
(default-cli) on project MYPROJECTNAME: The parameters 'file' for goal
org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are
missing or invalid ->
I just want to find out why it doesn't work? Looks like I am messed with phases and goals..
Finally I went another way: I placed it into my parent POM, but why it works with parent and doesn't work with child?
The best way to deal with a separated jar is to start using a repository manager and install this jar via the UI into the repository manager. From that point you can use as a usual dependency. Makes life easier.
If you like to install it as part of the build what you have tried that means you need to call maven like this:
mvn package
You should not mix up calling goals without life cylce like install:install-file with life-cycle parts as initialize.
That is the reason why you got the described error message, cause the command line part needs required parameters which you didn't gave on command line.
Combination like:
mvn install:install-file initialize
Make in Maven no sense (rarly). You have bound the maven-install-plugin to the life-clycle in your pom so you should simply call the life cylce:
mvn initalize
And you will get something like the following:
[INFO] ------------------------------------------------------------------------
[INFO] Building test 0.6-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default) # test ---
[INFO] Installing /home/mvntest/lib/jdom-1.0.jar to /home/.m2/repository/com/soebes/test/jacob/1.1/jacob-1.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.780s
[INFO] Finished at: Sat Oct 25 12:19:30 CEST 2014
[INFO] Final Memory: 6M/91M
[INFO] ------------------------------------------------------------------------
BUT: I have to say that installing an artifact like you did is bad practice. Best is to use a repository manager like Nexus, Artifactory or Archiva or if really don't like repository managers (I don't understand why, but this is a different story) you can use Stephen Connolly's non-maven-jar-maven-plugin
Apart from all the above you should use more up-to-date versions of maven-install-plugin which current version number is 2.5.2

Eclipse maven-jar-plugin not signing, because of duplicate entries pom.xml and pom.properties only on Windows

I searched a lot, but I have not found any solution for this.
Environment
*** Eclipse Java EE IDE for Web Developers. Version: Kepler Release - Build id: 20130614-0229 with m2e-wtp - Maven Integration for WTP
1.0.0.20130612-1742
*** Windows 7 up to date
*** Java SDK 1.7.0-40
*** Maven: Embedded (3.0.4/1.4.0.20130531-2315)
Problem
Errors:
Signing jars with (apache)maven-jar-plugin:2.4:sign (signing) on Linux works fine! The same maven project on Windows leads to the following error:
[INFO] jar is unsigned. (signatures missing or not parsable)
[ERROR] jarsigner: unable to sign jar: java.util.zip.ZipException: duplicate entry: META-INF/maven/.../pom.xml
Other messages:
I spotted different outputs between Linux and Windows from (apache)maven-jar-plugin:2.4:jar (default-jar)
Linux-Eclipse skips both files, because were already added:
...
[INFO] META-INF/maven/com.xyz/abc-client/pom.xml already added, skipping
[INFO] META-INF/maven/com.xyz/abc-client/pom.properties already added, skipping
...
after that the signing works fine!
The Windows ouput is not showing these two lines!!
Additional Information:
I can not use the (apache)maven-jarsigner-plugin, because it will lead to following error - without solution:
[ERROR] jarsigner: cannot rename file jarfile.jar to .orig`
This github-forum website tells me that the m2e-wtp-plugin of
Eclipse causing the problem, and that I should use maven on command
line .... this is the absolutely last option to use!!!
There is also a bug "MPIR-286" on codehouse for this, but still unresolved.
The clean part is done by the plugin and it's the same configuration for a client-module build before the one causing the problem.
Question:
Is there a possibility to get rid of this error? I cannot use the jarsigner-plugin, because of the "rename"-error and not the jar-plugin, because of the "duplicate entry"-error ... that is in fact a very strange situation.
This is the solution by the question's author, moved to the appropriate section.
To question's author: if you want to gain reputation, feel free to write a new answer, then ping me to remove this answer.
So I found it out myself. Here is what helped me to fix the problem.
Research
I found this question after more research and they stated, that the maven.archiver is the cause, because it wants to create the both files after they have been copied into the jar from m2e.mavenarchiver-plugin.
"... the m2e.mavenarchiver is creating pom.xml files etc. in the target directory, then these get pulled in by the maven archiver maven plugin, which then also creates its own files - hence the duplicates."
So the solution is also stated on this topic site.
Solution
Add
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
to your pom.xml
In my case
maven clean install fixed this issues
Make use of this Java Decompiler
for Viewing the jar whether it has a Duplicate pom.xml and properties
I have added below plugin that worked :
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>

Sonar Maven Plugin: How do I exclude test source directories?

I have a Maven project with Java sources and Scala test sources. I generate code coverage using Jacoco during the verify stage. When I try to run the sonar goal either during the verify phase by adding an execution, or by running mvn verify sonar:sonar, I end up with the test directory being added twice by Sonar:
[INFO] [11:15:34.756] Test directories:
[INFO] [11:15:34.756] /Users/xxx/Documents/workspace/misc/xxx/src/test/scala
[INFO] [11:15:34.756] /Users/xxx/Documents/workspace/misc/xxx/src/test/scala/../scala
which results in the analysis failing with the following error:
Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project kv-mapper: Can not execute SonarQube analysis: Unable to read and import the source file : '/Users/xxxx/Documents/workspace/misc/xxx/src/test/scala/../scala/xxx/xxxxx/xxx/xxx/xxxxx/xxxxxx.java' with the charset : 'UTF-8'. Duplicate source for resource
My pom.xml (for Sonar) looks like this.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.plugin.version}</version>
<!-- no default executions -->
<configuration>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>java</sonar.language>
<sonar.jacoco.itReportPath>
${basedir}/target/jacoco.exec
</sonar.jacoco.itReportPath>
<sonar.exclusions>
**/test/*
</sonar.exclusions>
</configuration>
</plugin>
How do I configure Sonar to either:
exclude test/scala directory entirely?
or
remove the duplicate directory?
sonar.test.exclusions should be used instead of sonar.exclusions
<sonar.test.exclusions>
**/test/*
</sonar.test.exclusions>
Either add a step to remove the folder before running the SonarQube analysis.
Or set exclusions on test files. See http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus#NarrowingtheFocus-IgnoreFiles

In PlayN, how do you exclude a directory from being compiled by Maven?

I want to build the html version of my game from the command line using maven. However, when I run the package command for the core folder:
mvn clean package -pl core,html
I get the following errors because of some unit tests in my source path:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/klenwell/projects/mygame/playn/mygame/core/src/main/java/mygame/playn/tests/unit/UserDataTest.java:[3,23] package org.junit does not exist
[ERROR] /home/klenwell/projects/mygame/playn/mygame/core/src/main/java/mygame/playn/tests/unit/UserDataTest.java:[7,16] package org.junit does not exist
...
How can I exclude the directory with these test files from being included in the compilation?
It is not a good idea to mix source and test classes. As per maven convention, you should move the tests from src/main/java to src/test/java.
You should add the dependency for junit so that the tests can be compiled.
You can choose to skip the tests (if they are broken) by using the -DskipTests or similar while running maven.
Adding the following block to the plugins section of my core pom.xml file excluded tests from compilation and allowed the build to succeed:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*Test*.java</exclude>
</excludes>
</configuration>
</plugin>

Resources