Increase heap size in m2e Eclipse plugin - eclipse

How does one increase the heap size of the m2e Eclipse plugin? Basically, I'm trying to run an automated integration test using Cargo and Selenium under STS (SpringSource's version of Eclipse) with pre-installed m2e (the popular Maven plugin for Eclipse).
Whenever I run
mvn verify
I get the infamous java.lang.OutOfMemoryError: Java heap space... 63M/63M. So I made some research first. Increase the memory via MAVEN_OPTS, Eclipse.ini / STS.ini, Run Configurations, and even via the Maven plugins thru the pom.xml. Nothing changed. Same error and same amount of memory 63M/63M.
I know my project works. The POM is correct. Why? Because when I run the same command using a stand-alone Maven. The integration test with Selenium and Cargo works. In fact here's the latest output (3 minutes ago):
[INFO] [beddedLocalContainer] Jetty 8.x Embedded is stopped
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 minutes 24 seconds
[INFO] Finished at: Wed Oct 26 14:08:16 CST 2011
[INFO] Final Memory: 70M/149M
[INFO] ------------------------------------------------------------------------
I'm not asking how to increase the memory in stand-alone Maven command. I'm specifically asking how to increase the heap size for m2e.
Note: By default the m2e Eclipse plugin does not have shortcut to the "verify" goal. You have to create a new one via Run Configuration (which does not have an Args tab, fyi).

When working with the Maven 2 plugin, setting java options in eclipse.ini or MAVEN_OPTS environment variable will have no effect on your build. You need to add some command line args via the "Edit Configuration and launch" dialog in Eclipse.
"Run As" > "Maven Build", click on the "JRE" tab, enter VM args e.g.
-Xms128M -Xmx512M

As a follow-on to the already accepted answer, when you invoke "mvn" on the command-line, you are really invoking the mvn.bat (or mvn.sh) wrapper script. It is this wrapper script that uses the MAVEN_OPTS env variable when kicking off the actual maven jvm.
m2e, on the other hand, wants more control over how the maven jvm is kicked off, so it does this directly without the wrapper. This is why you add your memory settings directly to your m2e run/debug configuration VM arguments, rather than using MAVEN_OPTS.
If you want m2e to pass what you already have in MAVEN_OPTS to the maven jvm, in the "Edit Configuration and launch" dialog in Eclipse:
"Run As" > "Maven Build", click on the "JRE" tab, enter VM args e.g.
${env_var:MAVEN_OPTS}

You can add in your pom.xml your memory settings:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
...
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
...
</configuration>
</plugin>
The description of all maven-compiler-plugin parameters is here: link

Have you tried setting the MAVEN_OPTS environment variable for your run configuration?
MAVEN_OPTS="-Xmx768M -XX:MaxPermSize=128m"
Might be you'll have to edit your system environment variables if setting it in the run configuration doesn't help. See here or here

I've faced a similar issue. Create a file named mavenrc_pre.bat on windows or .mavenrc on linux in your home folder and set your maven_opts as you wish in it.
It is working with m2e bundled with Eclipse Indigo.

Related

How does Eclipse apply an Expose Package configuration to a Maven build?

How does Eclipse propagate Java 11 "Expose Package..." to the Maven target?
I am exposing a Java 11 module to ALL-UNNAMED using Eclipse: Properties -> Java Build Path -> Module Dependencies -> Expose Package...
Nothing is added to pom.xml with this configuration yet the project builds successfully.
Using Eclipse 2020-06, m2e's maven 3.6.3, maven-compiler-plugin 3.8.1 (this is the only explicit override in pom.xml). The rest is the "EMBEDDED" maven.
When I look at the Maven console and effective pom I do not see any compilerArgs (--add-exports...) added. When I run mvn from the command line I do get compiler failure as expected.
How does m2e propagate --add-exports to javac without it being visible to help:effective-pom target or Maven console?
In Eclipse when I click "Show JPMS Options..." it does display "--add-exports ...", but nowhere in the m2e debug output does this appear.

IntelliJ Cannot Import sbt Project

I have upgraded IntelliJ to version CE 2017.3 from a CE 2017.2.5, and now I cannot build my sbt project. The build gets stuck on the first step:
"Build: sync
MyProjName: syncing...
dump project structure from sbt"
I have deleted the .idea directory and the the MyProjName/project/target directory. I did an sbt build from the command line, which worked.
Then I started IntelliJ again and tried to import MyProjName/build.sbt as a project. I have also logged out/in. Did this several times. The import never progresses past this step.
I work behind a firewall, but I have checked my proxy settings, and they are correct and unchanged from the previous version (if this matters).
How can I troubleshoot / fix this?
The sbt version is 0.13.6. Scala plugin 2017.3.10.
From the log:
IDE: IntelliJ IDEA (build #IC-173.3727.127, 27 Nov 2017 09:32)
OS: Windows 7 (6.1, amd64)
JRE: 1.8.0_152-release-1024-b6 (JetBrains s.r.o)
JVM: 25.152-b6 (OpenJDK 64-Bit Server VM)
I solved the sync issue following info here:
https://youtrack.jetbrains.com/issue/SCL-13024
Key info is "It seems that sbt is trying to re-resolve 'sources' and 'docs' for sbt plugins that are not available at all. If properties to download "Library sources" and "sbt sources" are disabled, then time to dump the structure is reduced from 'forever' to less than 1 minute."
That is , in IntelliJ IDEA, clear the check box "Library sources" under "Project level settings" for Build Tools sbt in IDEA preferences. As shown in image below:
The only way I could work around this was by running sbt clean compile in the SBT console/cmd line first, then refreshing the SBT project in IntelliJ.
Open a terminal inside IDEA by pressing Alt F12 or use sbt shell
Run sbt - if it is first time it will take some time.
Run clean
Run compile - it will download dependencies you have in your project.
Close IDEA project (File -> Close Project) and open it again.
Note: if it asks to import in the right-bottom of the screen activate Enable auto-import, if you don't like to keep it enabled (like me) press Import, cancel the syncronyzation and then Refresh sbt project again. When you try to use import in the middle of a sync it gets stuck with dump project structure from sbt message.
The Refresh sbt project is located at this corner of the Build Sync window - highlighted below:
I have not found a way to make this work in IntelliJ Idea CE 2017.3, so I have reverted to CE 2017.2.5
IntelliJ appears to limit the efficiency of the already slow sbt update. I recommend using sbt-coursier instead. It was written specifically to improve dependency update time, and on one large project I'm involved in it improved dependency update time by about 2 orders of magnitude.
Uncheck "Use auto-import" in Preferences > Build, Execution, Deployment > Build Tools > sbt to prevent IntelliJ from auto updating imports on its own
Add addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3") to your project's build.sbt file
Or install it globally in ~/.sbt/1.0/plugins/build.sbt
Run sbt update on the command line
If you see [error] java.lang.NoClassDefFoundError: org/vafer/jdeb/Console, then add the following to ~/.sbt/1.0/sbt-coursier.sbt.
import coursier.Keys._
classpathTypes += "maven-plugin"
See coursier issue #450 for more information about that error.
(Optional) Re-enable auto-import from step 1, as subsequent transactional dependency updates may be faster.
I meet the same problem! I delete the directory ~/.sbt/0.13, then it works. You can delete the sbt directory you used.
What worked for me was to increase the memory for SBT inside IntelliJ. On my Mac: preference -> Build, Execution, Depoyment -> sbt
then change "Maximum heap size" from 768MB to 2048MB and then everything was successfully imported after few minutes.
Custom SBT version works for me.
IntelliJ IDEA Preferences -> Build,Execution,Deployment -> Build Tools -> sbt -> Launcher
Choose Custom
For me, simply checking use sbt shell for both build and imports worked.
Had an older checked out project causing this issue. Did the usual rm -rf .idea + re-import but it kept getting stuck. Tried all sorts of things, but when finally fixed it for me was not just deleting the top-level target folder, but instead doing
find . -name target -type d -exec rm -rf {} \;
Next open / import went flawlessly. (This was on 2018.1.5, 2018.1.6 and 2018.2 RC.)
I have suffered from same problems after upgrade intelliJ to 2017.3
But it works fine now.
I think intelliJ couldn't pass the 'No proxy for' option to sbt.
so, I added
-Dhttp.nonProxyHosts="host1|host2"
option in File > Settings > Build, Excution, Deployment > sbt > VM parameters
Simply unchecking 'sbt sources' did the trick for me
I was also facing this issue. Below two configurations worked for me. I tried to confirm this setting in many new sbt projects, for all it worked.
(1) uncheck "Library sources" under "Project level settings" for Build Tools sbt in
IDEA preferences
(2) -Dhttp.nonProxyHosts="host1|host2"
option in File > Settings > Build, Excution, Deployment > sbt > VM parameters
I hit similar issue but found it's related to waiting for locks
~/.sbt/tool/sbt.boot.lock
~/.ivy2/.sbt.ivy.lock
Maybe if killing IntelliJ IDEA and no one will release the lock files, the issue is resolved after deleting locks files manually

Running out of memory with gwt:run-codeserver

I have a large GWT application that I'd like to test through Super Dev Mode.
When running the app with
mvn gwt:run-codeserver
it will compile OK and provide the URL for the server. At this point I fire up my app in a web browser and try to compile it again use the bookmarklets. This second compile brings up a range of memory errors like:
Caused by: java.lang.OutOfMemoryError: Java heap space
...
[ERROR] Out of memory; to increase the amount of memory, use the -Xmx flag at startup (java -Xmx128M ...)
So it's no secret that I need to assign more memory to the Java process running the server. What I can't work out is how to do that.
I have the following in my pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.maven.version}</version>
<configuration>
<extraJvmArgs>-Xmx2048M -Xms1024M -Xss1024k -XX:MaxPermSize=256M -XX:PermSize=128M</extraJvmArgs>
</configuration>
</plugin>
My MAVEN_OPTS environment variable is set to
MAVEN_OPTS=-Xmx2048M
And I have tried executing maven with
mvn -Dgwt.extraJvmArgs=-Xmx2048M gwt:run-codeserver
I have also tried it with the Oracle JDK and the open source JDK supplied with Fedora.
Nothing makes any difference. What am I doing wrong here?
UPDATE
I can confirm that this is an issue with the Maven plugin, and not the code. Running the project using IntelliJ's built in support for Super Dev Mode allow me to compile and recompile the application just fine. So this boils down to knowing the correct way to increase the memory that the Maven plugin has access too. It is obviously not one of the ways I have tried above...
Ok, so this was my fault. The POM.XML had some settings for the gwt plugin used when compiling against a profile, which had the memory settings configured correctly, and then another set of gwt plugin settings not tied to a profile (which I had not noticed).
So when I was compiling for a specific profile (the app server), everything was fine. The settings defined in the profile were being applied, and everything worked as you would expect. But when I running in superdevmode without any profiles set, the second, less specific settings were being used over and above anything I was setting on the command line.
I ended up debugging the problem using the -X maven flag, which dumps out the configuration actually used by the gwt plugin. If anyone has the same problem, look for the output like the sample below. From this you can tell what setting was finally applied, which you can then use to find out where it is set.
[DEBUG] --- exit fork of org.jboss.pressgang.ccms:pressgang-ccms-ui:1.0-SNAPSHOT for org.codehaus.mojo:gwt-maven-plugin:2.5.1-rc1:run-codeserver (default-cli) ---
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal: org.codehaus.mojo:gwt-maven-plugin:2.5.1-rc1:run-codeserver (default-cli)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<bindAddress>${gwt.bindAddress}</bindAddress>
<codeServerPort>${gwt.codeServerPort}</codeServerPort>
<extraJvmArgs default-value="-Xmx1024m">-Xmx1024m</extraJvmArgs>
<gen default-value="${project.build.directory}/.generated">${gwt.gen}</gen>
<genParam default-value="true">${gwt.genParam}</genParam>
<generateDirectory default-value="${project.build.directory}/generated-sources/gwt"/>
<gwtSdkFirstInClasspath default-value="false">${gwt.gwtSdkFirstInClasspath}</gwtSdkFirstInClasspath>
<inplace default-value="false">${gwt.inplace}</inplace>
<jvm>${gwt.jvm}</jvm>
<localRepository>${localRepository}</localRepository>
<logLevel default-value="INFO">INFO</logLevel>
<module>${gwt.module}</module>
<persistentunitcache>${gwt.persistentunitcache}</persistentunitcache>
<persistentunitcachedir>${gwt.persistentunitcachedir}</persistentunitcachedir>
<pluginArtifacts>${plugin.artifacts}</pluginArtifacts>
<project>${project}</project>
<remoteRepositories>${project.remoteArtifactRepositories}</remoteRepositories>
<style default-value="OBF">${gwt.style}</style>
<version>${plugin.version}</version>
<warSourceDirectory default-value="${basedir}/src/main/webapp"/>
<webappDirectory default-value="${project.build.directory}/${project.build.finalName}">${gwt.war}</webappDirectory>
</configuration>

Maven surefire arguments when running JUnit test via eclipse

A newbie question on Maven - Surefire - Eclipse - JUnit
I have configured the maven-surefire-plugin in the pom file of my project to pass some additional JVM arguments as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-d64 -Xms128m -Xmx4096m -XX:PermSize=512m -Duser.timezone=UTC -XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
When I run a test case of this project from Eclipse as Run As->JUnit Test, though the classpath is correctly set, the additional arguments specified in the argLine are not included in the invocation. I have to go and manually key in the arguments under the relevant Debug Configurations. I don't quite understand how JUnit is aware that it needs to put jars of the test scope on the classpath and in some way means that JUnit tool in Eclipse is aware of Maven via M2E? If so, how can we make it also read argLine. I know this sounds very specific - but how do others manage in similar situations?
Thanks in advance!
Eclipse JUnit Launcher (choose Run As -> JUnit Test) is a independent test runner which has its own pre-defined build and running life cycle and has nothing to do with Maven, it will not pick up your pom magically and read in the surefire configuration and use them to drive the test running.
If your project is imported as an existing Maven project, use Maven (choose Run as -> Maven test) launch your JUnit test which will pick up and use the surefire configuration. This is exactly same as running mvn test from commandline, it only output run log in console and you will not able to use the nice red & green JUnit UI window.
Hope this make sense.

"Plugin not found for prefix" error in Eclipse

In Eclipse I imported a maven-based project which uses maven jetty plugin. If I run mvn jetty:run from command line, everything works fine. If I add a run configuration in Eclipse and try to run it, I get the error message:
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/eugene/.m2/repository), central (http://repo1.maven.org/maven2)] -> [Help 1]
In the Eclipe run configuration, I use:
Base directory: ${project_loc}
Goal: jetty:run
Maven Runtime: External
I read the [Help1] page. I don't have pluginGroup settings in maven configuration files, but I have the jetty plugin mentioned in pom.xml, so I guess everything should be fine (especially because everything works in command-line). I tried to "Run as > Maven clean" in Eclipse before executing the jetty run configuration, but it didn't help. Project compiles and passes all tests, only jetty:run does not work in Eclipse.
Please help, I'm an Eclipse & Maven newbie. Thanks in advance.
It does not work for me from command-line either.
Can you check if it works after adding the following in settings.xml as documented?
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
Also note that there are two different versions of the plugin - the older maven jetty plugin and the newer jetty maven plugin.
I met this problem too, an easier way to solve this is to edit your pom.xml, add following plugin:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.6.8.v20121106</version>
</plugin>
...
</plugins>
</build>
...
</project>
Note:
jetty-maven-plugin is used for jetty version 7 and above, if you want jetty version 6, you should use maven-jetty-plugin
for the version, you may want to have a look at here and here for your desired version's full name.
I apologize for wasting your time. Now I looked through maven warnings which appeared in Eclipse console after I ran the run configuration. I noticed
[WARNING] Failed to retrieve plugin descriptor for Plugin [org.mortbay.jetty:maven-jetty-plugin]: null
so it became obvious why it couldn't recognize jetty: prefix. Couple of lines above I saw a bunch of warnings about missing plugin versions. So I added a version specification for the jetty plugin (<version> entry in pom.xml) and it solved the problem. I forgot a common rule that if something breaks the first thing to check is warnings you get.
I've got this issue in eclipse after importing an appengine project.
The target:
mvn appengine:devserver
The error:
[ERROR] No plugin found for prefix 'appengine' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/averasko/.m2/repository), central (http://repo.maven.apache.org/maven2)] -> [Help 1]
The problem was in the incorrect base directory in the eclipse run configuration. When maven does not see a pom.xml file and is asked to run some non-standard target if fails like this as it don't know anything about the plugin that defines the target.
The solution is to correct the base directory to wherever your pom.xml file resides.
if you following this tutorial:
http://tapestry.apache.org/creating-the-skeleton-application.html
don't forget to follow this one crucial instruction:
Change into the newly created directory, and execute the command: