How to add XX:PermSize to every run config - eclipse

Recently all my runs of my java code eclipse have been giving me permMem errors.
I can fix this with adding
-XX:PermSize=128M -XX:MaxPermSize=256M
to the dun/debug config, but I don't want to keep doing this. My eclipse config has:
eclipse.vm=C:\Windows\system32\javaw.exe eclipse.vmargs=-Xms384m
-Xmx768m
-XX:MaxPermSize=384m

You can make your VM options to be shared by new run/debug launches by adding you options to Launching Arguments.
It is explained here.
Edit:
My first answer was about plug-in development, sorry about that. You can add shared vm options by:
Window->Preferences->Java->Installed JREs->Select Your JRE->Edit->Add your vm arguments to Default VM Arguments
This adds your VM arguments to your Java application run/debug configurations.

Related

CQ5 debug bundles using eclipse won't halt

I created a bundle that I already uploaded, but I would like to debug it.
I started the server with debug mode:
java
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -XX:MaxPermSize=256m -Xmx1024M -jar AEM_6.0_Quickstart.jar
Then I set to the project that packaged into the bundle its remote debugging configuration. But when I set the breakpoints in the project, it won't halt where it needs to when the lines are executed.
Below are some steps that can be helpful. Use that command line to start your CQ instance.
java -jar cq5-author-4502.jar -fork -forkargs -- -Xdebug -Xrunjdwp:transport=dt_socket,address=59865,suspend=n,server=y -Xmx1520m -XX:MaxPermSize=512m -XX:-UseSplitVerifier
I have simple title component in which I am calling some service method. And applied some breakpoints in service. I have multi-module eclipse project practice. Setup eclipse debug configurations as shown below :
Inside source add project's module as shown below :
Click on the debug button and refresh the cq page. You will see below image:
Open the Eclipse in debug prospective you can see you variables over there and page still loading as you not complete the method execution.
Hope this will Help!!
Thanks
Replace CQ_JVM_OPTS at cq5/aem directory >> crx/bin/start
CQ_JVM_OPTS='-server -Xmx1024m -XX:MaxPermSize=256M -Djava.awt.headless=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=30303,suspend=n'
Increase the heap size which is allocated to CQ process.
Make XX:MaxPermSize=512m and try.

How to change default JRE for all Eclipse workspaces?

I have one JRE in C:\Program Files (x86)\Java\jre6 and that was the only one at the time I installed Eclipse. I have subsequently installed a complete JDK in C:\home\SFTWR\jdk1.6.0_21 and changed my JAVA_HOME environment variable to that. However, every time I start a new Eclipse workspace, it only picks up the old JRE and I have to manually remove it and add the new one.
How do I bind my Eclipse install to the new JDK so that every new workspace points to that only? I checked eclipse.ini but there was no reference there to which JRE to go to.
UPDATE:
I went into Prefs->Java->Installed JREs, added the new location, marked it as default, removed the other, and it was effective only for the current workspace. However, when I opened a new workspace, only the old JRE was available. So this didn't change the core Eclipse config that is applicable across all (at least new) workspaces
Finally got it: The way Eclipse picks up the JRE is using the system's PATH.
I did not have C:\home\SFTWR\jdk1.6.0_21\bin in the path at all before and I did have C:\Program Files (x86)\Java\jre6\bin. I had both JRE_HOME and JAVA_HOME set to C:\home\SFTWR\jdk1.6.0_21 but neither of those two mattered. I guess Eclipse did (something to the effect of) where java (or which on UNIX/Linux) to see where Java is in the path and took the JRE to which that java.exe belonged. In my case, despite all the configuration tweaks I had done (including eclipse.ini -vm option as suggested above), it remained stuck to what was in the path.
I removed the old JRE bin from the path, put the new one in, and it works for all workspaces.
The Installed JREs is used for what JREs to execute for your downstream Java projects and servers. As far as what JVM or JRE that is used to execute Eclipse process (workbench) itself that is controlled by your environment, history and eclipse.exe binary. So eclipse.exe itself decides what JRE Eclipse will execute itself with, not installed JREs preferences since those are not read until OSGi framework is up and running which is loaded after the JVM/JRE is picked.
So for new workspaces, Eclipse is going to use its currently executing JRE to populate the JRE prefs.
The best way I know how is to force eclipse.exe to use the JRE that you tell it via the -vm switch. So in your eclipse.ini do this:
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
-vm
/path/to/exactly/what/jre/you/want/as/default/javaw.exe
...
Open the Java > Installed JREs preference page. Check the box on the
line for the JRE that you want to assign as the default JRE in your
workbench. If the JRE you want to assign as the default does not
appear in the list, you must add it. Click OK.
Source-http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-assign_default_jre.htm
In eclipse go to
Window-> Java -> Installed JREs
You can remove your current installed jre and add the jdk by specifying the path to where the jdk is installed.
I ran into a similar issue where eclipse was not using my current %JAVA_HOME% that was on the path and was instead using an older version. The documentation points out that if no -vm is specified in the ini file, eclipse will search for a shared library jvm.dll This appears in the registry under the key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment that gets installed when using the windows java installer (key might be a bit different based on 64-bit vs 32-bit, but search for jvm.dll). Because it was finding this shared library on my path before the %JAVA_HOME%/bin, it was using the old version.
Like others have stated, the easiest way to deal with this is to specify the specific vm you want to use in the eclipse.ini file. I'm writing this because I couldn't figure out how it was still using the old version when it wasn't specified anywhere on the path or eclipse.ini file.
See link to doc below:
http://help.eclipse.org/kepler/topic/org.eclipse.platform.doc.isv/reference/misc/launcher.html?cp=2_1_3_1
Finding a VM and using the JNI Invocation API
The Eclipse launcher is capable of loading the Java VM in the eclipse process using the Java Native Interface Invocation API. The launcher is still capable of starting the Java VM in a separate process the same as previous version of Eclipse did. Which method is used depends on how the VM was found.
No -vm specified
When no -vm is specified, the launcher looks for a virtual machine first in a jre directory in the root of eclipse and then on the search path. If java is found in either location, then the launcher looks for a jvm shared library (jvm.dll on Windows, libjvm.so on *nix platforms) relative to that java executable.
If a jvm shared library is found the launcher loads it and uses the JNI invocation API to start the vm.
If no jvm shared library is found, the launcher executes the java launcher to start the vm in a new process.
-vm specified on the command line or in eclipse.ini
Eclipse can be started with "-vm " to indicate a virtual machine to use. There are several possibilities for the value of :
directory: is a directory. We look in that directory for:
(1) a java launcher or
(2) the jvm shared library.
If we find the jvm shared library, we use JNI invocation. If we find a launcher, we attempt to find a jvm library in known locations relative to the launcher. If we find one, we use JNI invocation. If no jvm library is found, we exec java in a new process.
java.exe/javaw.exe: is a path to a java launcher. We exec that java launcher to start the vm in a new process.
jvm dll or so: is a path to a jvm shared library. We attempt to load that library and use the JNI Invocation API to start the vm in the current process.
My answer will overlap with amphibient's while adding on to it.
Your JAVA_HOME variable is fine, but you also need to append the following to your Path variable :
;%JAVA_HOME%\bin
This will allow your applications in your Windows environment to access your JDK. You should also restart your computer once you've added these environment variables before checking out if they work. In my case, even logging out and then back in didn't work : I had to completely restart.
If you want to check if the environment variables are set correctly, you can open up a command prompt and type >echo %JAVA_HOME and >echo %Path% to see if those variables are working correctly. While snooping around for solutions, I have also run into people claiming that they need to add quotations marks (") around the environment variables to make them work correctly ("%JAVA_HOME%"\bin) if your JAVA_HOME path includes spaces. I thought that this was my case at first, but after doing a full restart my variables seemed to work correctly without quotation marks despite the spaces.
when you select run configuration, there is a JRE tap up next the main tap, select "Workspace default JRE(JDK1.7)".
Be sure to use the jdk in Prefs->Java->Installed JREs ->Execution Environment
I have faced with the same issue. The resolve:
- Window-->Preferences-->Java-->Installed JREs-->Add...
- Right click on your project-->Build Path-->Configure Build Path-->Add library-->JRE system library-->next-->WorkSpace Default JRE
try to change the order:
right click on you project-> BuildPath->Configure...->Order and Export tab -> move jre7 UP.
I navigated to:
Eclipse>Pref>Java>Installed JRE>Search...
2 of them popped up and I checked the latest one. Before I did this I also went to About>Check for Updates and updated it. I didn't have to reinstall any JRE or JDK either. I might have done it a while back, except it was with 1.6 not 1.4. Hope that helps!
On windows I've tried different approaches
- setting JAVA_HOME, JRE_HOME and extending the PATH to point to the desiered jre18 but nothing helped
- disabling the JRE17 in the java control panel didn't helped either
What helped me out was to force eclipse to use the appropriate JRE in the eclipse.ini file e.g.
-vm
C:\java\jdk1.8.0_111\jre\bin\javaw.exe
#Stefan Michev answer also worked for me,
edit eclispe.ini to point to your installed JRE
-vm
C:\Program Files\Java\jdk-18.0.1.1-openj\bin
but to elaborate;
My application server uses JAVA_HOME and thus PATH so I needed Eclipse to pick up another JRE to run (so to be compatible with an installed plugin).
This Eclipse JRE is different than
than setting Window-> Preferences -> Java -> Installed JREs which as you see in the below image, is for building Java projects, so you can have different projects with different JDKs
Eclipse Installed JREs

Debug eclipse plugin project -- PermGen space, out of memory error

I have a plugin project. When i debug this as an eclipse application, in the 2nd eclipse that opens, I want to open Project explorer window. As soon as I click on the button to do this, I get java.lang.OutOfMemoryError: PermGen space. I tried changing the PermGen space in the preference, but it did not help. Can any one please suggest a solution.
You should add the -XX:MaxPermSize=256m or 512m to the Window>Preferences>Java>Installed JREs preference page. Edit a JRE and add it to the Default VM arguments tab.
The eclipse native launcher uses the eclipse.ini to add extra permgen arguments to Oracle JVMs, but that information is not used during runtime launching.
What if you try to extend the memory of eclipse when it starts. To do that simply open the .ini file (inside your eclipse folder) and edit the lines that refer to permSize and memory size:
e.g.
-XX:MaxPermSize=500m
-Xms500m
-Xmx2000m
If you don't want to set the permgen size for EVERY launch, you can also add the Parameter to the Debug Configuration.
Run > Debug Configurations
Choose the "Eclpise Application"-Configuration on the right side and choose Arguments in the Tabs.
Add -XX:MaxPermSize=512m to the VM arguments:
-Dosgi.requiredJavaVersion=1.6 -Xms256m -Xmx4g -Dfile.encoding=UTF-8 -XX:MaxPermSize=512m

problem in linking viewer selection with current editor - Eclipse

I often get this error "Operation linking viewer selection with current editor finished with errors" in Eclipse Galileo.
Once this error pops up no UI events is working in the IDE , i cant even able to close it also. Every time i have to go to task manager to stop the process , after this IDE works fine for some 5 min and again it display the same error as mentioned above.
i don't know what is happening , can you guys please help.
Just switch your Project Explorer to the Flat package presentation in Eclipse. It works :)
see details here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=530450#c7
Per the Eclipse manual:
PermGen is the permanent generation of objects in the VM (Class names, internalized strings, objects that will never get garbage-collected). An easy, if somewhat memory-hungry fix is to enlarge the maximum space for these objects by adding
-XX:MaxPermSize=128M
as an argument to the JVM when starting Eclipse. The recommended way to do this is via your eclipse.ini file.
If you are getting OutOfMemoryErrors while running Eclipse, the VM can be told to let the heap grow to a larger amount by passing the -vmargs command to the Eclipse launcher.
-vmargs
-Xms512m
-Xmx1024m
Alternatively, you can invoke the Eclipse executable with command-line arguments directly, as in
eclipse [normal arguments] -vmargs -XX:PermSize=512M -XX:MaxPermSize=1024M -Xmx1024M [more VM args]
Even with recent versions of Eclipse and Flat Package presentation, if you have a lot of large projects loaded this can still be a problem.
I've found however that if you break up your projects into working sets and minimise the amount of projects/tree nodes open by selecting a working set it can really speed up Eclipse and mitigate this problem.
I had this problem (Version: Photon Release (4.8.0)) and I fixed it by removing all breakpoints.

How to make eclipse launch a program in the eclipse workbench from the command line?

How do I make eclipse launch a program in the eclipse workbench from the command line?
Specifically, I would like to run a command from the shell that causes my eclipse instance (which is already open) to run a particular program. If there is no program to do this from the shell, is there some RPC API that eclipse provides to make such a program?
I do not want to make a plugin. It must be a separate process that controls eclipse.
Eclipse Remote Control seems that it might do the trick https://github.com/marook/eclipse-remote-control from the Read me file.
Introduction
Eclipse plug-in project which adds remote control features to eclipse.
Commands can be sent via the eclipse remote control client to a
running eclipse instance.
I have not tried it myslef but I ran into it trying to figure out how to write an ant task that triggers .launch file
First create a batch file and save it in a location.
For example if I want to invoke notepad , I will write in the batch as follows
start notepad
In eclipse, you can configure external tools.
Goto Run -> External Tools -> External Tools Configurations.
You will be presented with a Dialog box.
Now Click on the New Configuration Icon.
In the right pane of Window you can assign a configuration Name.
In the Location Text Box, Click on the "Browse File System" Button, and select the batch file you have created earlier.
In the Common Tab, uncheck "Launch In Background".
You can set this configuration in Favourites menu, by clicking the checkbox "External Tools" under Common Tab.
Click on Apply.
Now you can Run your required application. This is for Windows only. I don't have any idea of this for Linux Machines.
Take a look at Product Configuration
1º Create a new Product Configuration (Ctrl+N), and select "Use a launch configuration" (or another option, if it's more convenient) on the first page of the wizard.
2º In the Exporting section you should be able to export your product using the "Eclipse Product export wizard".
3º To run the product, follow this instructions
Hope it helps.
Not a complete answer, but here are some things I've come across with Eclipse:
In general, you can open Eclipse from the command line with something like:
java -Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -Xms40m -Xmx512m -XX:MaxPermSize=256m -cp plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar org.eclipse.core.launcher.Main
That Main launcher takes an -application flag where you can pass what I think are plugins (not sure). I've typically used this to run Ant within Eclipse:
java -Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -Xms40m -Xmx512m -XX:MaxPermSize=256m -cp plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar org.eclipse.core.launcher.Main -application org.eclipse.ant.core.antRunner -buildfile build.xml
I have no idea how to manipulate a running Eclipse instance, and I don't know if you can achieve your goals through an Ant script, but I thought these might be fruitful avenues.
Addition to ams' answer, marook's plugin just support very few commands.
open_file and execute_command with RUN/DEBUG/PROFILE
And marook also have a blog post about how to implement more command http://pielmeier.blogspot.com/2010/07/implementing-new-eclipse-remote-control.html
But as we all know, Eclipse plugin development is quite heavy weight.
So, I suggest just use execute_command with RUN by marook's plugin. The further function to Eclipse IDE, can be done by Eclipse EASE script engine. Write a light weight script and then RUN by marook's plugin, to avoid Eclipse plugin development.
More information about EASE can be found at:
https://opensource.com/life/16/2/how-use-python-hack-your-ide
There is also javascript script support:
https://git.eclipse.org/c/ease/org.eclipse.ease.scripts.git/tree/JavaScript%20Beginner%20Tutorial/02%20File%20IO/05%20Create%20sample%20project%20(using%20modules).js
Here you have a series of examples: http://www.rgagnon.com/javadetails/java-0014.html
Basically, you use:
Runtime.getRuntime().exec(command);