OpenJDK Needs More Memory in Gradle Project [duplicate] - java

I have an application. I run it via
gradlew run-app
Or debug
gradlew debug-app
It works. How do I pass '-Xmx' argument into the application which I run (debug)?
Is it possible to do so without edditing build.gradle file?
I found this
Gradle unknown command-line option '-X'
I get a similar error when I try
gradlew debug-app -Xmx2000m
Error
FAILURE: Build failed with an exception.
* What went wrong:
Problem configuring task :debug-app from command line.
> Unknown command-line option '-X'.
I tried to create a file gradle.properties in GRADLE_USER_HOME directory (by default, it is USER_HOME/.gradle).
org.gradle.jvmargs=-XX\:MaxHeapSize\=4256m -Xmx4256m -Xms2000m
I also tried to org.gradle.jvmargs=-Xmx2000m in project folder gradle.properties.
And even then when I run an application, I see Commited Memory size is < 520 MiB
And this is when I run it as a normal Java App
In the second case, when I run the application as a normal Java app with -Xms, -Xmx, Commited Memory size is about 3.5 GiB because I passed -Xmx4512m -Xms2512m parameters.

Add this in your gradle.properties file :
org.gradle.jvmargs=-Xmx2000m
From here
org.gradle.jvmargs
Specifies the jvmargs used for the daemon process. The setting is
particularly useful for tweaking memory settings. At the moment the
default settings are pretty generous with regards to memory.
edit : my answer what about the gradle daemon jvm, not the app jvm. You have to use the jvmArgs property
The extra arguments to use to launch the JVM for the process. Does not
include system properties and the minimum/maximum heap size.

Firstly, thanks #ToYonos for leading me to the right direction.
Secondly, I found the solution here https://stackoverflow.com/a/9648945/4587961.
I ran my app from command line.
set GRADLE_OPTS=-Xms1724m -Xmx5048m
gradlew debug-app
Note, CMD Windows command SET works locally, so if you close your terminal, GRADLE_OPTS will not be set. For Linux, you can use
export GRADLE_OPTS=WHATEVER
This is what I wanted to achieve.

Using application plugin one can use applicationDefaultJvmArgs property
apply plugin: 'application'
applicationDefaultJvmArgs = ["-Xms1024m", "-Xmx2048m"]
The arguments will be applied to run task and to start script of your application
more info

In my case Invalidate cache and restart the android studio(which is automatically restarted) then the error will be gone after restarting the android studio
then

Related

Customize Spring Boot executable-jar startup script

I'm trying to run Spring Boot executable-jar built using spring-boot-maven-plugin on a Linux machine. The machine has multiple jdks installed, the one on PATH is jdk8 and changing it is unfortunately not an option. My executable-jar however needs jdk17, so when I just launch it as is I get UnsupportedClassVersionError.
I was following the official documentation and created the corresponding .conf file to override JAVA_HOME. But this does not seem to solve the issue:
[root#ios-maket updater-new]# ls
updater-new-3.0-SNAPSHOT.conf updater-new-3.0-SNAPSHOT.jar
[root#ios-maket updater-new]# cat updater-new-3.0-SNAPSHOT.conf
JAVA_HOME=/opt/jdk-17/bin/java
[root#ios-maket updater-new]# ./updater-new-3.0-SNAPSHOT.jar
Application is running as root (UID 0). This is considered insecure.
Exception in thread "main" java.lang.UnsupportedClassVersionError...
On the other hand if I run it manually everything works fine:
[root#ios-maket updater-new]# /opt/jdk-17/bin/java -jar ./updater-new-3.0-SNAPSHOT.jar
[main] INFO com.icl.ios.fias.updaternew.UpdaterNew - Starting UpdaterNew using Java 17.0.6
What am I doing wrong?
Setting JAVA_HOME is not enough, you also need to set PATH to point to JAVA_HOME/bin.
JAVA_HOME=/opt/jdk-17
PATH=${JAVA_HOME}/bin:$PATH
java -jar updater-new-3.0-SNAPSHOT.jar
Try running the jar with -Dloader.path to specify the config manually.
java -Dloader.path=./updater-new-3.0-SNAPSHOT.conf -jar ./updater-new-3.0-SNAPSHOT.jar
If this still does not work, then probably there is an issue with your config file, but from what I can see, your config file looks okay, unless the java path is incorrect.

IntelliJ IDEA Gradle sync: Problem with setting Gradle's Java home to some JDKs

I have no problem with:
org.gradle.java.home=C:/Program Files/Java/openjdk1.8.0_202
in my (global) gradle.properties file. Also, no problem without it (with nothing set). But if replace it with one of below configurations (all paths are valid):
org.gradle.java.home=C:/Program Files/Java/openjdk-9.0.4
org.gradle.java.home=C:/Program Files/Java/openjdk-10.0.1
org.gradle.java.home=C:/Program Files/Java/openjdk-11.0.1
org.gradle.java.home=C:\\Program Files\\Java\\oraclejdk-11.0.1
then I will get an error message (same for each) after I save the file and import Gradle changes in IntelliJ IDEA:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/5.0/userguide/gradle_daemon.html
Please read the following process output to find out more:
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Error: Could not find or load main class java.base.java.lang=ALL-UNNAMED
Caused by: java.lang.ClassNotFoundException: java.base.java.lang=ALL-UNNAMED
The note is the issue is only for IDE Gradle sync. Gradle tasks themselves work correctly (independent from IDE)! Even when I run gradle --status (see here about it) can see everything is OK and daemon is running using JDK 11:
>gradlew --status
PID STATUS INFO
10668 IDLE 5.0
And the path of PID: 10668:
>wmic process where "processId=10668" get Name, ProcessID, ExecutablePath
ExecutablePath Name ProcessId
C:\Program Files\Java\openjdk-11.0.1\bin\java.exe java.exe 10668
Finally, I found out the issue was from my IDE settings. It was from SDK Table.
I don't know why correcting them from Project Structure (or Structure for new Projects in Other Settings) couldn't solve the issue. Finally, I imported it (and only it) from a fresh installation.
Note: You don't need a fresh installation really. Just enough to close your IDE, rename its configuration directory and re-open it.
Then IDE starts freshly. This is an opportunity for the test. If OK export pointed setting ... File -> Export Settings ...:
to a file. Then return to your previous state and import the exported file:
If the issue reverted you need to check other settings (other than SDK Table).

Apache Ofbiz installation trouble

I have been trying to install Apache Ofbiz on my 32-bit processor computer, with Windows 7 as the operating system. I have downloaded Java\jdk1.8.0_25: and apache-ant-1.9.4: and :apache-ofbiz-13.07.01. I made two environmental variables, JAVA_HOME and ANT_HOME; in addition, I included both Java and Ant Apache Bin addresses respectively into the environmental the PATH variable. Then I ran the CMD and entered the Ofbiz directory' cd [apache ofbiz address], thenceforward, I resumed into entering the the 'ant run-install' command, followed by 'ant run-install-seed', I received a 'build successful' message for both of the commands I entered. After the foregone commands were executed I proceeded into clicking the startofbiz located inside the apache ofbiz folder. A cmd screen opened listing all sorts of commands. Once all these were carried out I typed the following address into my internet search bar:
https://localhost:8443/webtools
Notwithstanding, I constantly received the following error message that says THE TEMPLATE LOCATION IS EMPTY even after a numberless amount of permutations, deleting java, re-installing Ant Apache, etc:
:ERROR MESSAGE:
org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen [component://common/widget/CommonScreens.xml#GlobalDecorator]: java.lang.IllegalArgumentException: Template location is empty (Template location is empty)
I have not been able to come to grasps with this issue. I don't believe things should be this difficult to install. I stand ready for any guidance, thank you.
As per my best knowledge " ant load-seed (Load ONLY the seed data (not seed-initial, demo, ext* or anything else); meant for use after an ualong with the code and needs to be in sync for operation)"
You need to fire ant load-demo start (if you're using OFbiz version 13.07.01).Please make your're at the root of the OFbiz project location. Fyi - At very first time it takes more than 20 mins to load all your demo data and seed data, so please be patient. Hope this will help you.
Note: Please rate this if find useful. Thanks
This issue is not related to your Application setup. it seems your Application setup is fine. This is related to Seed data. The data which requires to initialize the default theme. To load the theme data, execute the following ant command then strat the application. The error should be disappeared now.
ant load-seed
Since OFBiz switched from ant to gradle recently, the correct command to load the seed data is as follows (run in root ofbiz folder e.g. /opt/ofbiz and don't forget the quotes):
./gradlew "ofbiz --load-data readers=seed"
To get the available options for the ofbiz build, run:
./gradlew "ofbiz --help"
Other ant-to-gradle hints can be found here.
You will then need to create an initial user (admin/ofbiz does only exist in demo data).
./gradlew loadAdminUserLogin -PuserLoginId=MyUserName

sbt won't assemble Spark

I am having issues assembling Spark using the sbt on my machine.
Attempting the assembly without allocating extra memory either runs out or times out on the garbage collector; the exact issue has been different at different times I have tried. However, any attempt to modify the allocated memory, either through Xmx or Xms, and whether giving more or restricting, fails as the sbt doesn't recognize -Xmx or -Xms as a command.
Here is a sample of the kind of command I have been trying (from the source directory of Spark):
sbt -Xmx2g assembly
Here is the error I have been receiving:
java.util.concurrent.ExecutionException:java.lang.OutOfMemoryError: GC overhead limit exceeded
Use 'last' for the full log.
Not a valid command: Xmx2g
Not a valid project: Xmx2g
Expected ':' (if selecting a configuration)
Not a valid key: Xmx2g
Xmx2g
^
I am running 64-bit Java, version 1.8.0_20.
Try creating a new environment variable SBT_OPTS, with the value "-XX:MaxPermSize=1024m". That should give sbt the memory it needs without producing your error.
Check the docs: Building Spark with Maven.
Setting up Maven’s Memory Usage
You’ll need to configure Maven to use more memory than usual by setting MAVEN_OPTS. We recommend the following settings:
export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m"
Then you can build it with:
mvn -DskipTests package

Netbeans Module Development out of memory

I am creating a module in netbeans to help with a project i am working on however when I run the module in the developmental IDE i get an out of memory exception while loading an asset. This procedure seems to work fine in the base netbeans environment but when i make the same calls during module development i get the error. After attempting to load the asset in several differnt ways i tried appending the following to project.properties and then to Netbeans Platform config(platform.properties)
netbeans_default_options="-J-Xms384m -J-Xmx1024m -J-XX:PermSize=32m -J-XX:MaxPermSize=96m -J-Xverify:none"
and also tried
netbeans_default_options="-J-client -J-Xverify:none -J-Xmx1024m -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true"
I have also tried
test.run.args=-ea -Xms1024m -Xmx1024m
I was stuck in this issue for a while. Adding this line into project.properties has solved the problem:
run.args.extra=-J-Xms128m -J-Xmx512m -J-XX:MaxPermSize=512m
While it improved the heap memory size, apparently the problem was gone because of the increased non-heap memory size (J-XX:MaxPermSize=512m).
Good luck
If the problem occurs when you install your module in the development IDE, you can configure the maximum heap size and perm size in <netbeans-install-dir>/etc/netbeans.conf by appending your -J-Xmx and -J-XX:MaxPermSize parameters to the netbeans_default_options variable. You should also append -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled, as noted in the docs (see http://wiki.netbeans.org/FaqGCPauses).
Had a similar memory problem on my Linux Debian.
Only Works on linux / possibly UNIX OS's???
Here is how to fix it:
run a terminal
log in as root
type crontab -e
scroll to the bottom or the file and type * * * * * sync; echo 3 > /proc/sys/vm/drop_caches
This magic line cleared all unused ram every minute. It removed the unused memory NetBeans was producing (including any other memory-consuming programs).
plz tell me if this works.
solution to Out of memory exception in netbeans is![.....][1]
I have tried by setting project properties.
right click on project --> select Properties-->General Settings-->VM Options
Add below parameters -Xms256m -Xmx512m

Categories