IntelliJ debugger does not pause at breakpoints on Maven project - java

Problem
Since yesterday, I am unable to launch a proper debug of my tests. Debugger happily jumps over my breakpoints. I validated that the code was actually executed by adding some logs.
What I've tried so far
Synchronize project
Clean, reinstall and rebuild the project
Purge Maven dependencies
Upgrade IntelliJ IDEA to the last version
Read IntelliJ docs about configuring debugger options
Browse questions that had been asked before, with no success (for instance here, here and here).
More info about the project
The executed Java code is in one of the folders declared as test sources (one is "java" for Selenium tests, other is "scala" for Gatling tests).
My Maven command line is pretty straightforward: package clean -Dtest=MyTestClass integration-test.
EDIT: My POM configuration does mention reuseForks and forkCount. I've also tried playing with deprecated forkMode, but with no success.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<skip>${skip.selenium.tests}</skip>
<parallel>none</parallel>
<threadCount>1</threadCount>
<reuseForks>false</reuseForks>
<forkCount>0</forkCount>
<disableXmlReport>false</disableXmlReport>
</configuration>
<executions>
<execution>
<id>runSeleniumTests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
What is funny, though: debugger actually stops at breakpoints when I right-click on the project root or on test sources root ("java" folder) and click on "Debug 'All tests'".
Any help... will help.

If you are using surefire plugin it runs your test in another process hence you are not able to debug.
Use forkMode=never in your maven configuration

Related

How to force maven to run build-lifecycle before site-lifecycle?

After spending several hours trying to find out whats the problem I come to the conclusion that I need to know:
How can I force maven to execute the lifecycle phases clean, build and site in exact this order: clean -> build -> site?
Problem / scenario:
I have to multimodule projects with identical moduls:
pSuccess
|-pSuccessClient
|-pSuccessEJB (has pSuccessClient as dependency)
|-pSuccessEAR (has pSuccessEJB as dependency)
and
pFail
|-pFailClient
|-pFailEJB (has pFailClient as dependency)
|-pFailEAR (has pFailEJB as dependency)
Both projects have distribution repositories for snapshots and releases in our central nexus artefact repository but none of them has been deployed to it, meaning the nexus is empty.
When I run mvn clean package site on the pSuccess-project the target directory is deleted (clean-lifecycle), then the modules are all build (build-lifecycle) and finally the reports are generated (site-lifecycle) correctly on the freshly build modules - BUILD SUCCESS! While "debugging" the process I figured out that during the build-lifecycle the needed clientDependency is placed in the lokal maven repository and then used for the EJB, same with the EJB for the EAR module. Working smoothly as expected.
But when I do the same on the pFail-project maven executes the site-lifecycle after the clean-lifecycle and before the build-lifecycle. As you can expect this results in a failed build as maven can't find the needed dependency (Client) for the EJB. This is quite locically as it hasn't been build yet. I can enforce this result every time I run the command. There's not phase of the build-lifecycle be run - no compilation, just nothing. Maven tries to execute the site-lifecycle first. The build is only successfull when I run a mvn clean deploy and then another mvn clean package site, becuase then the artefact is read from the nexus. But again site-lifecycle is executed before build-lifecycle. Note Building the project only via mvn clean package works fine without any problems. All modules are build in the correct order. But when I add the site lifecycle it fails.
I read the maven documentation about lifecycle but I can't figure out why site is run before build. In some questions here on SO I read that plugins, which shall be executed in the same phase, are executed in the order they are listed in the pom.xml. So I checked that too, but the <build> tag is definied before the <reporting> tag.
So why is maven executing the site-lifecycle before the build-lifecycle in one of my project and how can I force maven to execute the lifecycles in the right order: clean -> build -> site ?
P.S: I run all maven commands on command line in windows 7.
edit
I know about the lifecycles and phases, meaning I know what's the differenze between package, install, deploy is - that is not part of the question!
For those who do not believe about the execution order: This is the output when I run mvn clean install site, showing that site-lifecycle is executed before build-lifecycle. It doesn't matter if I run mvn clean package site or mvn clean install site. Again, running single mvn clean package(or install) works fine, but not when I want to generate site too. Then site is executed first.
After digging several more hours I found a solution for my problem:
Both projects use the maven-javadoc-plugin during for reporting
<reporting>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.version}</version>
<!-- DocLint je nach Profil ausschalten (siehe oben) -->
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
</plugin>
...
</reporting>
In the EJB of the failing project we also use the build-helper-maven-plugin in the generate-sources phase of the build lifecycle.
<build>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
....
</plugin>
...
</build>
It seems that both plugins collide during the generate-sources phase.
After chaning the maven-javadoc-plugin to use the following ReportSet the site generation works fine
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.version}</version>
<!-- Disable DocLint correspondening to java version -->
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>javadoc-no-fork</report>
<report>test-javadoc-no-fork</report>
</reports>
</reportSet>
</reportSets>
</plugin>
I still don't really understand why it collades but at least my project is working.

How to generate separate jar files for application, source, and documentation (for central.sonatype.org)

Sonatype has a repository that I want to deploy a jar file to, and they ask for separate files for application, sources, and javadocs:
Example:
example-application-1.4.7.pom
example-application-1.4.7.jar
example-application-1.4.7-sources.jar
example-application-1.4.7-javadoc.jar
In Scala SBT, I have a command called "package" that generates the jar file for the project, but that only generates "example-application-1.4.7.jar".
Question: What should I do to generate the other two jar files?
In Maven, in order to get the additional -sources and -javadoc artifacts, add to your POM file the following:
<build>
<plugins>
<!-- additional plugin configurations, if any.. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note the snippet above:
We are invoking the Maven Source Plugin to create an additional jar files for sources
We are invoking the Maven Javadoc Plugin to create an additional jar files for javadoc
Executing
mvn clean package
You will find these two additional jars in the target folder.
The .pom file instead is generated during the install phase, but it is not placed under the target folder. Basically, it is a copy of your pom.xml file, with a different extension and used by Maven during the dependency mediation process to check which transitive dependencies are required by the concerned artifact.
Executing
mvn clean install
Maven will install the artifact in your local cache (in your machine), under path_to_cache/.m2/repository/your_groupId/your_artifactId/your_version/. In this folder, you will also find the .pom file, which normally you don't need to distribute (it is created automatically by Maven).
Further note: you probably don't want to generate these additional jar files at each and every build, so to speed up normal builds and have them only on demand, you could wrap the snippet above in a Maven profile.
You can achieve this by removing the snippet above from your build section and add a further section at the end of your pom:
<profiles>
<profile>
<id>prepare-distribution</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
So that normal builds would not create these jars anymore, but when executing the following:
mvn clean install -Pprepare-distribution
You would instead get them back. the -P option is actually activating on demand the profile defined with the id prepare-distribution.
With Maven 3 a default profile already comes as part of the super pom which perform exactly the same actions (sources and javadoc artifact), hence no need to add anything to your existing project. Simply run:
mvn clean install -Prelease-profile
Or, to activate it via a property
mvn clean install -DperformRelease=true
However, as also specified in the super pom, this profile may be removed in future releases (although there since first Maven 3 version till version 3.3.9 so far)
NOTE: The release profile will be removed from future versions of the super POM
The main reason behind this warning is most probably to push for the usage of the Maven Release Plugin, which indirectly makes use of this profile via the useReleaseProfile option of the release:perform goal.
As highlighted by comments, if you are not familiar with maven (especially via console) I would definitely recommend to
Go through the official Maven in 5 minutes documentation for a quick but worthy look.
Play with Maven from the command line, is there where Maven gives you its best. IDE integrations are great, but command line is the real turning point.
Then play with the POM customization above, to get familiar with some concepts and behaviors, first directly as part of your default build, then moved to a profile.
Then, and only then, move to the Maven Release Plugin usage. I recommend it as last step because you would already have acquired more confidence and understanding and see it as less magic and more reasonable approach.

Maven won't run my Project : Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec

I can't run the Maven Netbeans JavaFX example :
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) onproject mavenproject3:
Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e
switch. Re-run Maven using the -X switch to enable full debug logging.
My POM looks like this :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.huw.almexoffice.client</groupId>
<artifactId>almex-office-client</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Almex Office Client</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.huw.almexoffice.client.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Does anyone know why this is happening?
And if not, does anyone know how to get Maven running with the -e or the -X switch via Netbeans? I assume it is via a right click on the POM and then run goal then entering something in the textfield there.
This error would spring up arbitrarily and caused quite a bit of trouble though the code on my end was solid.
I did the following :
I closed it on netbeans.
Then open the project by clicking "Open Project", selecting my project and
Simply hit the run button in netbeans.
I would not build or clean build it. Hope that helps you out.
I noticed another reason why this happens. If you moved your main class to another package, the same error springs up. In that case you :
Right Click Project > Properties > Run
Set the "Main Class" correctly by clicking "Browse" and selecting.
I faced the same issue. When I tried to run the project from IDE, it was giving me same error. But when I tried running from the command prompt, the project was running fine. So it came to me that there should be some issue with the settings that makes the program to Run from IDE.
I solved the problem by changing some Project settings. I traced the error and came to the following part in my pom.xml file.
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
I went to my Project Properties > Actions Categories > Action: Run Project:
then I Set Properties for Run Project Action as follows:
runfx.args=-jar "${project.build.directory}/${project.build.finalName}.jar"
Then, I rebuild the project and I was able to Run the Project. As you can see, the IDE(Netbeans in my case), was not able to find 'runfx.args' which is set in Project Properties.
what's happening? you haven' shown much of the output to be able to decide. if you are using netbeans 7.4, try disabling Compile on Save.
to enable debug output, either run Custom > Goals... action from project popup or after running a regular build, click the Rerun with options action from the output's toolbar
I am a beginner in Maven - don't know much about it.
Carefully check on your input i.e. file path in my case.
After I have carefully check, my file path is wrong so it leads to this error.
After I fixed it, it works magically lol.
A solution which worked in my case is:
1. Go to the module having Main class.
2. Right click on pom.xml under this module.
3. Select "Run Maven" -> "UpdateSnapshots"
Had the same problem, I worked around it by changing
${java.home}/../bin/javafxpackager
to
${java.home}/bin/javafxpackager
Had the same problem after installing oracle jdk on Ubuntu 13.10 x64.
I've done the following steps, not sure which one helped. I think that at least 2 and 3 are necessary.
Deleted Netbeans 7.4 and reinstalled it from oracle's site.
Installed plugins for maven, ant and java that may be related to the project.
Deleted .nbproject folder - after that the project was considered a maven project.
Also, after that, I've found that the project runs, but exits with exit code 1 because I didn't supply the command line parameters for it. And the builder considers it is an error. So, look carefully for the output and see if the program actually starts.
Maven needs to be able to access various Maven repositories in order to download artifacts to the local repository. If your local system is accessing the Internet through a proxy host, you might need to explicitly specify the proxy settings for Maven by editing the Maven settings.xml file. Maven builds ignore the IDE proxy settings that are set in the Options window.
For many common cases, just passing -Djava.net.useSystemProxies=true to Maven should suffice to download artifacts through the system's configured proxy. NetBeans 7.1 will offer to configure this flag for you if it detects a possible proxy problem. https://netbeans.org/bugzilla/show_bug.cgi?id=194916 has discussion.
I solved this issue with right click on project -> Set as Main Project.
Netbeans needs to be able to index the maven repository. Allow it to do that and try again. It was giving me the same error and after it indexed the repository it ran like a charm
Try to run Maven from the command line or type "-X" in the text field - you can't break anything this way, at the worst, you'll get an error (I don't have Netbeans; in Eclipse, there is a checkbox "Debug" for this).
When running with debug output enabled, you should see the paths which the exec-maven-plugin plugin uses.
The next step would then be to copy the command into a command prompt or terminal and execute it manually to see if you get a useful error message there.
Restart Netbeans & it solved my problem.
Im new to java hibernate but i could solve this problem, this is how i did it :
I was working with hibernate and maven project.
First you have to put persistence.xml under project directory, then add jdbc manually.
Maven couldn't download my dependency so i added it manually.
In the persistence.xml in design jdbc connection add it manually ps: i work with netbeans good luck
For me, the clue was the "org.codehaus.mojo:exec-maven-plugin:1.2.1:exec".
The only place this was referenced was in the "Run project" action under Project Properties=>Actions.
When I changed this action to match the HelloFXMLWithMaven sample project (available in Netbeans 11.1):
"clean javafx:run"
then executing the Run goal was able to proceed.
Note, I also had to update the pom file's javafx-maven-plugin to also match the sample project but with the mainClass changed for my project.
Rohith H.Y Solved this problem
I noticed another reason why this happens. If you moved your main class to another package, the same error springs up.
In that case you :
Right Click Project > Properties > Run
Set the "Main Class" correctly by clicking "Browse" and selecting.

Eclipse Maven Plugin fails to create groovy-maven-archetype project

I have installed the Maven for Eclipse plugin from Sonatype.
(update site: http://m2eclipse.sonatype.org/update/)
I am creating a Maven project, and choosing to use the groovy-maven-archetype as my starting point.
However, halfway through, I am seeing:
04/03/09 12:52:28 GMT: [FATAL ERROR]
org.codehaus.mojo.groovy.stubgen.GenerateStubsMojo#execute()
caused a linkage error (java.lang.NoSuchMethodError). Check the realms:
... snip ...
Realm ID: plexus.core
org.codehaus.plexus.PlexusContainer.createChildContainer
(Ljava/lang/String;Ljava/util/List;Ljava/util/Map;)
Lorg/codehaus/plexus/PlexusContainer;
How can I fix this?
At a command prompt, enter this: mvn archetype:generate
Then, choose 40 (gmaven-archetype-basic)
Then, follow the prompts.
Once you have a maven project, you can enable Eclipse support by saying: mvn eclipse:eclipse
You can read Building Groovy Projects for more information.
Seems like a versioning problem to me. Are you sure you used all the right versions of the jars?
Getting Groovy-Eclipse, gmaven, and Eclipse all working together seems to be pretty tricky at the present. Once you've got a project created with mvn archetype:generate, as AWhitford mentions, this site will show you a few of the tweaks you'll need to make it work.
GMaven's stub creation for Java files interferes with Groovy-Eclipse, hence the section on that page about commenting out stub creation. However, I went with the method mentioned in the comments for the relevant bug (GMAVEN-61) and created multiple executions for the gmaven plugin, like so:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-3</version>
<!-- http://jira.codehaus.org/browse/GMAVEN-61 -->
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>stubsonly</id>
<goals>
<goal>generateStubs</goal>
<goal>generateTestStubs</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm still not certain myself that this is clean for both pure Maven usage as well as within Eclipse, but it at least got me to the point where I stopped spending hours trying to get anything to work and got me coding on my actual project.
The Groovy-Eclipse and GMaven documentation are good reading for background info.

Generating a maven site including a Cobertura Report

I've got some projects that are already doing site generation via maven, and I want to integrate cobertura reports in them, but no maven goal I seem to run will generate a local preview for me to look at that includes the Cobertura reports in the site. I want to be sure they're generating correctly before I commit the pom changes to the repo and have broken site generated.
Below is what I've added to the maven poms (parent and module), but the site I see when I run mvn site:run does not include the cobertura reports:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<check>
<haltOnFailure>false</haltOnFailure>
<regexes>
<regex>
<pattern>parent-package-name-here.*</pattern>
<branchRate>80</branchRate>
<lineRate>80</lineRate>
</regex>
</regexes>
</check>
<instrumentation>
<includes>
<include>parent-package-name-here/**/*.class</include>
</includes>
</instrumentation>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
...
</project>
What maven command should I use to generate the site with cobertura reports? Or, what should I add (additionally) to get the site generation to include the cobertura reports?
Should do:
mvn site
To elaborate, running mvn a:b runs the goal b in plugin a. Saying mvn c means to run the lifecycle phase c, which runs all of the bound goals in all of the phases up to c. As a result, this will trigger a lot more things to happen (such as doing the necessary preparation to produce cobertura reports).
I figured out how to do this.
It seems there are a lot of bugs in the link generation within the maven site generation plugin.
The only way I've found to make maven generate a local copy of the site with working module links is to modify the distributionManagement/site tag to point to some local directory instead of the real-live deploy directory, then use maven site:deploy.
Every attempt to use mvn site:stage generates broken links. Same goes for mvn site:run.
The report links work with mvn site:run / mvn site:stage but the links to modules do not.
mvn site
should do what you are looking for. You configure the plugin to run in the pre-site and site phases of the life cycle but your are then executing the site:run goal not site. We are doing similar things with clover (commercial coverage tool) and mvn site does the trick.
site:stage module links don't work in my experience either for multi module builds but site:deploy does. Try this:
Use a property for the site URL in the parent pom, e.g. ${site.url}. Then call this
mvn clean site site:deploy -Dsite.url=file://`pwd`/target/site-deployed
The pwd is a -nix command that will substitute the current directory. This is because the URL that you use must be absolute.
We use
mvn site-deploy
This builds the site and deploys it (copies it to the place we have configured).
mvn site:site should produce what you are after, in the target directory, there will be a site directory containing all reports linked with an index.html in that directory.

Categories