While developing some plugins based on Eclipse, I need to add some default VM arguments when user right click-> "run as" -> "java application" or "spring boot app", is there any open api I can call or any extension point?
Just like the snapshot below, the argument "-Daaa=bbb" is added by default.
Any help is appreciated.
You need to write your own plugin and need to replicate/extend Java launch configuration
(of type Java application) from JDT and add -vm argument programmatically.
But there is one more easy way: Try LcDsl.
LcDsl provides a way of defining Eclipse launch configurations in a textual way. The file extension used is '.lc' It provides some obvious and some non-obvious advantages over the Eclipse launch configuration solution.
For more info look here and check demo videos. Also there was a discussion going on to include this plugin in JDT itself, see this bug entry.
A typical Java launch configuration looks like this:
java configuration LcJavaMain {
project com.wamas.test;
main-class com.wamas.test.JavaMain;
memory min=64m max=256m;
vm-argument '-Dmy.arg=value';
argument 'cmdArg';
}
Related
I am trying to setup my JavaFX enviroment so I referenced the corresponding Jars. In order to run the code I need to use some VM Arguments
("vmArgs": " --module-path /Users/adrif/Downloads/javafx-sdk-14.0.2.1/lib --add-modules javafx.controls,javafx.fxml")
in the launch.json. I am working in a multi-project folder so every time a make a new one I have to go to the launch.json and add the arguments. How do I set global arguments? I found adding arguments in "launch" at user settings.json (Launch - Global debug launch configuration. Should be used as an alternative to 'launch.json' that is shared across workspaces)
but doesn't work as I expected.
As you can see, I have two JavaFX projects under the package JavaFX.
And every time I run a new project I have to add the vmArg line to each project.
This is the "launch" options but as I said, it doesn't work or there's someting wrong with how I'm trying to do it. So as the title sais, how to I set global arguments?
Edit : I found the "java.jdt.ls.vmargs" option which allows to specify extre VM Arguments. I does not work either.
Solved, turns out it was fixed in newer versions of Vscode and it's pertinent Java Extensions. The workaround that I used was just adding a new set of arguments for every file in the project.
"vmArgs" was JVM related, "java.jdt.ls.vmargs" was java language server related, the language server was contained in the "Language Support for Java(TM) by Red Hat" extension, so it will not work.
The "launch" configuration in settings.json I tried in local and does not work too.
VSCode has not provided this feature for the present, You need to configure the "vmArgs" for each project. This is because the launch.json file contains different language debugging settings, and lots of configuration was exclusive to some language.
I have successfully run annotation processor for CLASS level retention annotations via command prompt compiling using Java 8.
However, when I tried to configure the annotation processor in eclipse and tried to run it with "-proc:only" option, it didn't get effective.
I have included the Jar file containing the custom annotation processor class file into the Project Properties -> Annotation Processing -> Factory Path. I have also provided the -proc:only option in Project Properties -> Annotation Processing -> Processor Options, still the annotation processor isn't getting called when a class containing my annotation is executed.
Please help me identifying the required setting or mistake or additional step for running the annotation processor via eclipse.
I was finally able to enable my own annotation processor by adding my jar file.
Right click on the project and select Properties.
Open Java Compiler -> Annotation Processing. Check "Enable annotation processing".
Open Java Compiler -> Annotation Processing -> Factory Path. Check "Enable project specific settings". Add your JAR file to the list.
Clean and build the project.
And it finally worked.
It is very much straightforward provided that whatever APT plug in you are trying to use is correctly configured.
Follow the steps mentioned in above post and the reference image to visualize it. Image showing QueryDsl APT configuration for maven project.
While compiling via command prompt or terminal, you can see all the logs in same screen after the compilation command. In eclipse, these logs can be seen at
Window->show view->General->Error Log
If you want the IDE(Eclipse) to point out the warning, error or other diagnostic message exactly at the particular element in the code editor, we have to call the printMessage method of javax.annotation.processing.Messager with 3 arguments as shown below.
messager.printMessage(Kind.ERROR, "Error Message", element);
As it is specified everywhere for executing robot scripts you have to create maven project.I created the maven project and have added all the dependencies and plugin required for the execution. But when i create the maven project then by default a class ic created as AppTest.java in my src/test folder.Now when i add this .robot file in my test folder or main folder.It is not getting executed.Moreover i have a confusion how to execute these scripts.Please help me with this.Where should i place these file so that they could be executed.
I believe that at this time (7 months after your question) you've found a solution for the problem. If yes, I suggest you share it with the community.
Here's my solution, assuming that you're using Google Chrome:
Open the Edit Configurations window for your maven project, select the tab "Parameters", and in the field "Command Line" type "robotframework:run". It should look like this:
Then you select the tab "Runner" and add the property "webdriver.chrome.driver=/path-to-the-webdriver". It shoud look like this:
(note: uncheck the "Skip tests" check box. Mine is checked on the screenshot because I was testing other things.)
What's a little frustrating is that we can be misled by the error messages which say that you have to set the environment variable "webdriver.chrome.driver". In this case, we're tempted to add this variable to the field "Environment variables".
However, IntelliJ creates its own environment on run. That's why the field "Environment variables" doesn't work. When you add that property to the "Properties" box, the IntelliJ will convert it into a parameter in the run command, which will create the proper environment for the project.
Something like this:
/usr/lib/jvm/java-8-oracle/bin/java
-Dmaven.multiModuleProjectDirectory=/home/acampos/study/robotframework01
-Dmaven.home=/home/acampos/programs/idea-IU-172.4343.14/plugins/maven/lib/maven3
-Dclassworlds.conf=/home/acampos/programs/idea-IU-172.4343.14/plugins/maven/lib/maven3/bin/m2.conf
-javaagent:/home/acampos/programs/idea-IU-172.4343.14/lib/idea_rt.jar=36889:/home/acampos/programs/idea-IU-172.4343.14/bin
-Dfile.encoding=UTF-8
-classpath /home/acampos/programs/idea-IU-172.4343.14/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher
-Didea.version=2017.2.5
HERE!!!
-Dwebdriver.chrome.driver=/home/acampos/programs/chromedriver/chromedriver robotframework:run
So, when you run your maven project it will run the goal that's described on the Parameters tab, Command line field.
I hope it helps. And, again, if you've found another solution, please share with us.
Good luck!
every now and then I am launching JUnit tests from within Eclipse by using
Run As > JUnit Plug-in Test
By default Eclipse assumes you are running something which requires a workbench and chooses in the "Main" section of the launch configuration
LaunchConfig > Main > Program To Run > Run an application >
org.eclipse.ui.ide.workbench
I can understand why this is the default, but for me (and for all in our team) this is never ever the case. We always need to run our JUnit Plug-in Tests as
LaunchConfig > Main > Program To Run > Run an application >
[No Application] Headless Mode
How do I change this default behaviour?
I am currently using Eclipse 4.4.
It seems a custom LaunchConfiguration-Extension is a viable solution attempt.
What I did was to create a new, custom LaunchConfiguration-Extension which is 99.999% build on the JUnitLaunchConfiguration. I only had to add a custom
BlaBlaJUnitPluginTestLauncher extends launching.JUnitLaunchConfigurationDelegate
which overrides the
launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
method to adjust the application parameters according to our needs.
BlaBlaJUnitPluginTestTabGroup extends org.eclipse.pde.ui.launcher.JUnitTabGroup
To be able to initialize the LaunchConfig dialog with the default parameter, I had to:
Add a custom BlaBlaPluginJUnitMainTab extends PluginJUnitMainTab
Create a custom JUnitProgramBlock implementation (BlaBlaJUnitProgramBlock)
Creating an instance of BlaBlaJUnitProgramBlock in the BlaBlaJUnitPluginTestTabGroup.BlaBlaPluginJUnitMainTab.createProgramBlock() method
Overriding setDefaults-method (not sure if its really neccessary) in BlaBlaJUnitProgramBlock
Overriding initializeForm-method in the BlaBlaJUnitProgramBlock and adjust parameter there too.
Leading to the following result:
This answer is a near miss:
Try this:
Manually create and configure one "good" launch configuration.
Next time you want to launch a test that doesn't yet have a good launch configuration:
Select the file and invoke Run As > Run Configurations ... (i.e., don't yet select JUnit Plug-in Test!)
In that dialog select a good launch configuration of the same kind, and ...
Then click New Launch Configuration (upper-left corner)
Now the newly created configuration should "inherit" the configured values from the the good configuration.
Truth is:
You can duplicate an existing launch configuration (leaving you to manually select the test to launch)
The Debug team once had plans to support launch configuration templates.
Edit 2018:
Since Eclipse Photon, the Java debugger supports launch configuration prototypes. I just filed Bug 536728 to request this also for test launches. Feel free to chime in (or contribute) on that bug.
if u r looking for only shortcut for convenience then eclipse remembers last execution. After using run as and saving ur run config, just use "Run as" button in toolbar.
besides this eclipse comes with flavour for testers, u can check that out.
Also since you are talking about unit testing see if you can make use of ant build or even better converting to maven based project. Maven has integrated support for testing.
There seems to be a simple and effective heuristic in place, which decides whether or not a JUnit Plug-in Test should be run headlessly or with an application:
Make sure that the plug-in containing your tests has no dependencies on anything org.eclipse.ui.
Without that dependency [No Application - Headless Mode] is selected by default for newly created launch configurations.
With that dependency the default is Run a product, with s.t. like org.eclipse.platform.ide preselected.
I'm writing a Java library with a lot of jni code. Pretty much every test case needs to load my jni dll, and I have a lot of test cases. In order to run the test cases out of Eclipse's Junit launcher, I have to create a run/debug configuration and edit the VM arguments and environment variables.
I would like a way to set the VM arguments and environment variables to a default for the entire project and have new run configurations include the default entries. From what I can tell, Execution Environments maybe do something like this but I seem to need the PDE to get them to work(?)
Specifically, I want to enable assertions on my project by default and include the path to my native dll in the PATH environment variable. I can't use the "Default VM Arguments" setting in the JRE definition panel because my dll depends on a number of others and java.library.path isn't used for dependency resolution, PATH is. Is there a way to make Eclipse do what I want?
So, here's what I did.
First, my specific problem was that I have a lot of run configurations, I create new ones on the fly, and I needed certain system properties set for unit tests. Setting them under the 'args' tab of run configurations was undesirable for my workflow. Also, I wanted the same command-line args set for all of my tests. I also don't run my app from inside eclipse. It's a dev-environment only.
So my solution was to add it to the command-line of my JRE. Preferences -> Java -> Installed JREs. Clicking edit gives you a window where you can specify default VM args. I just set the system properties I need for testing there.
Hope this helps.
How long does it take to run all of your tests for the project?
If the answer is Not long then create a project-wide JUnit launcher. If occasionally you would need to do a run on a single test case ( in order to debug or something ), you can copy all your settings from the project's junit launcher. I think you can even clone your project launcher to run a specific test case.
Run->Run Configurations...
Create new JUnit launcher.
On 'Test' tab select Run all tests
in selected {...}
Connfigure JVM options, classpath,
environment etc. for this launcher
Optional, but highly recommended. On
Common tab -> Save as -> Shared
file, and check-in launcher with
your project
One more thing I would do is to define a system property in launcher VM arguments, check for this property in #Before function and throw exception if the property is not set. This way you will know that your test fails because it is not using the right launcher.
If I understand your question correctly, I think Alexander is on to the idea with cloning the project launcher. Eclipse lets you duplicate launch configurations with a single click - simply setup one configuration with the parameters you require and click the button in the top left to duplicate it whenever you create a new one.