Eclipse default when multiple ways to run exist [duplicate] - java

Whenever I hit Debug or Run in Eclipse, I get a dialog asking me what configuration I want to use.
How do I set a default configuration and bind a keyboard shortcut?

Maybe this article from Eclipse One Tips will help you:
How to run the last launched application
The answer lies in a preference hidden on the Run/Debug page:
Go to Window > Preferences > Run/Debug > Launching.
Select the option Always launch the previously launched application. It’s located at the bottom of the dialog.
The preference should look something like this:
Now you’re free to press
F11, Ctrl+F11 or click the Run/Debug
icons on the toolbar with confidence, knowing it’s going to run what
you expect it to run.
One question arises: How do you quickly run a class as a specific
application (eg. a JUnit test) if you can’t press F11 to
run it? You have some options available:
The fastest way is to use keyboard shortcuts. Eclipse allows you to launch classes using a keystroke, including JUnit tests, Java
applications, etc using Alt+Shift+X.
Alternatively, right-click on the class and select Run As. The submenu will show available options for launching the class.
Lastly, you could click the pulldown arrow on the run/debug icons in the toolbar and select Run As. The submenu once again shows
available options for launching the class.

Eclipse plug-ins that add new project types may contribute 'Launch Configurations' to control how Eclipse executes the application. For example, J2EE based projects need to publish content and start the application server. Contrast this with simply starting a JVM for a regular Java application.
When you select a configuration, Eclipse records this for future use. You can access these by selecting the 'Run/Run Configurations' menu item or selecting 'Run Configurations' from the little drop down menu next to the run and debug toolbar buttons. You can also add new launch configurations through the Run/Debug Configurations dialog that opens. In this dialog, you should see one or more configurations that you previously launched. Selecting one reveals all the info Eclipse uses to launch your application. One tab called 'Common' contains options for controlling the your favorites menu. Checking the box next to Run or Debug will add this launch configuration to the top of its corresponding menu.
If you only have a single configuration in your menu then Eclipse will launch it when you click the associated button. If you have more than one then Eclipse launches (sometimes) the most recently used. I say sometimes because, occasionally, one launch configuration causes another to launch, which cause the last used configuration to be the second one when you would expect it to be the first one. Usually this happens to me when I launch an application, which needs to be built and the build launches a tool. When this happens, just select the correct launch configuration from the drop down menu.
You can bind a keystroke combination to the Run and Debug commands through the 'Windows/Preferences' menu item. Then select 'General/Keys' in the tree control on the left.

Related

Eclipse maven launch "has encoutered a problem" No selected resource

Developing a Maven project in Eclipse, when I click the launch button, the launch will often fail with the error:
'Launching project_name' has encountered a problem.
No selected resource
This is because I have not selected a Java class file in the editor before clicking the Launch button (little green play icon).
Usually, I have the maven console, or Git staging view in focus at the time I press the button, so I understand why it is happening, just not how to prevent it.
Surely the play button knows which project to select. Why should it care which view has focus when I press the button? The launch configuration refers to the project via a value like ${project_loc:project_name} in the Base directory field.
Is there a way I can tell Eclipse to just run the maven build, regardless of what focus the IDE has?
I am running Eclipse IDE for Enterprise Java Developers.
Version: 2018-12 (4.10.0) on Ubuntu.
In Window > Preferences: Run/Debug > Launching choose Always launch the previously launched application as Launch Operation.
Make also sure not to use selection based variables like ${git_branch} without an argument.
To make git_branch independent of the selection, specify the resource (file or folder) from which you want to have the current branch name. For example, ${git_branch:/my_project}.

intellij idea - cannot run "Tomcat" project on linux

When I configure Tomcat in "Run configuration" in intellij, button "Tomcat" does not become active, as a result I can't run the project. I do not have any message about some errors. I went thorought many tutorials (even the most simple), but all was unsuccessful.
Here some screens
It appears as though you are looking at the default setup. Not an actual configuration.
Click the green plus icon at the top of that list to open the 'Add New Configuration' menu, and select Tomcat>Local from there (you may need to click the 'X items more' option if it is not shown initially).
This will create a deployable config of tomcat based on the default setup you have shown here.

Stanford CS106a: some java applet errors that do not allow to run the programs

Wasnt able to solve the problems in this screen.
http://s8.postimage.org/n5osf76ed/qestions.jpg
All the code worked a month ago.
What have I changed: I have a different version of eclipse (now: Eclipse IDE for Java Developers 1.5.1.20120920-0737, don't know what the previous one was).
Messed with environment variable. Since this does not effect the ot
Please help.
Try this solution mentioned in this discussion.
I just ran into this problem using standard (not Stanford) Eclipse.
By now this is probably moot for you, but I'll post my solution for
future travelers.
The launch configurations for Assignment 1 default to Applet, so the
containing Karel application isn't launched. To solve this, create
and use new Application launch configurations for each file.
If you already tried to run some of the files, delete the Applet
configs created so you can reuse the names:
Open the project properties (e.g. right click on Assignment 1 and select Properties).
Select Run/Debug Configurations.
Select and Delete each configuration.
Click OK.
May the Force be with you.
Create Application configs:
Right click on java file (e.g. CollectNewspaperKarel.java) and select Run As > Run Configurations...
Select Java Application in the left pane.
Click New Launch Configuration (the icon of a document with a +).
Type a name for the configuration and set its Main class to the associated file (e.g. CollectNewspaperKarel).
Click Apply then Run. (This should run correctly and create a useful entry in the Run History.)
Eclipse will still try to default to Applet, so you will henceforth
need to launch these configurations from the Run History (either from
the Run menu or the pull down on the run button). If you accidentally
launch as default, it will add a useless Applet configuration to the
Run History (e.g. CollectNewspaperKarel (1) ). You can delete this
from the Run Configurations dialog to keep the Run History tidy.
The eclipse used in CS106A is customized for stanford and for "karel the robot" :)
Just download and install it again and things should work just fine.

Make eclipse debug my android PROJECT

I am writing an Android application using Eclipse. When I click on the project in the left tree view and then click debug, the IDE builds an APK and installs in the emulator / device as expected.
However, if I'm editing a file and forget to first click on the project before attempting to debug, the IDE thinks I want to debug that specific Java file. This is NOT what I want to do, I would like it to build and emulate / install on device as usual.
Is there any way to change this behavior in Eclipse?
In eclipse, you can set in workspace preferences / run-debug / launching to always launch the previously launched application (until you explicitly choose an other application: then it will be the last that will be launched).
This way, no matter where you press (ctrl)F11 or click the debug/run button, the launch configuration you used the last time will be called again.
You will still be able to launch different applications of course, by explicitly calling their launchers (the way you debug now).
The procedure you are using (clicking on the project and selecting Debug as => Android Application is OK, for the first debug session (resp. Run as, non debug).
If you want to debug the app again (regardless of what is selected in the left hand side navigator), you should just click on the Green Run circular icon (or rather on the small > sign on its right side if you want to select a different run configuration) or the little bug on its left (for debug).
If you click on one of the > you will select on of the 8 last run/debugged app. If you are sure that the last one is the one you want to run again, then just press one of these two icons (bug for debug, green arrow for run) instead of the arrows.
When you click on the project and select Debug as what you actually do is configure a default run configuration for this app or class that can be later tweaked through the Run/debug Configurations... to better suit your customisation needs. If you click again, eclipse will detect that it has already generated a default configuration (and will not create a new identical one). Alternately you can directly create your new Run/Debug config directly through the Run/debug Configurations... sub menu.
Since the ADT plugin shipped by Google does not include a Run as... Android Application submenu when you click a java class under an android project, the default launch configuration is the java application or the server application (static main method absent).
Update
To clarify things a bit. What you ask (running your android app whilst having the java class selected in the package explorer is possible). What happens when you press the 'small bug' icon does not depend on what is selected in any navigator.
The "default launch configuration" is poorly phrased.
Let me describe what happens in more detail. When you right-click on a java class say in the package explorer (or the project explorer for Java EE version) eclipse (the navigator) calls all contributions (plugins) having registered a handler for that event and lists possible candidates in a sub menu.
In a standard Java EE eclipse installation you will see at least the run on server option and if the class has a main static method with string array arguments, you will also have a the runs as ... java application option. In both cases, eclipse will generate for you a "launch configuration". These launch configurations (both debug and non debug) are all available in the launcher dialog boxes (accessible via the icons described above). They have a lot of different configuration options depending on their nature (for instance whether you debug on a server or a simple java app or an applet). What I termed the "default configuration" is that for each of this launch configuration categories, eclipse will leave these options empty.
So the first time, you will select the Android project and select the run as... Android application option. This will create a default configuration. In ADT's case, the default configuration will also probably select a default ADV and launch it (if it's not already launched). And on subsequent occasions, it will be enough to press the run or debug icon to redeploy your app back to your ADV and this will happen regardless of what is selected in the navigator.

How to launch multiple Java programs with one configuration on separate consoles (with Eclipse)

I'm working with a Java program that has multiple components (with Eclipse & Ant at the moment).
Is there some way to start multiple programs with one launch configuration? I have an Ant target that does the job (launches multiple programs) but there are things I would like to do:
I would like to debug the programs with Eclipse, hence the need for Eclipse launch.
I would like to see the outputs for the programs at separate consoles.
Also other ways to launch multiple Java programs "with one click" with separate consoles and/or debugging would be ok.
['multiple launch part':]
If you have an ant launch configuration which does what you want, you can always transform it into a java launcher calling ant.
Main Class: org.apache.tools.ant.Main
-Dant.home=${resource_loc:/myPath/apache_ant}
-f ${resource_loc:/myProject/config/myFile-ant.xml}
You can then launch this ant session as a regular java application, with all eclipse debugging facilities at your disposal.
Add to your classpath in the User Entries section (before your project and default path):
ant.jar
ant-launcher.jar
[Multiple console part]
May be a possible solution would be to make sure your ant launcher actually launches the different application in their own JVM process (one javaw.exe for each application)
That way, you could use the ability of the native eclipse console to switch between different process.
The Console view clearly separates output from each distinct "process" and keeps them in several "buffers". The Console has a built-in "switch" feature that will automatically switch the view to display the buffer of the last process that performed output, however you can easily switch the display to any "process buffer" you want to look at.
To switch the Console "buffer" display, just click on the black "Down arrow" next to the 4th toolbar button from the right in the Console View's title bar (the button
that resembles a computer screen):
this will show a pop-down menu listing the "names" of all active process buffers, preceded by an "order number".
The one currently displayed will have a check-mark before its "order number". You can switch the view to another display buffer simply by clicking on its name.
The question and selected answer here are both 6 years old.
Eclipse Launch Groups provides UI to run multiple launch configs. Launch Groups is apparently part of CDT but can be installed separately without CDT by installing "C/C++ Remote Launch" (org.eclipse.cdt.launch.remote).
There's actually a ticket opened at Eclipse site which requests this very same functionality. One of the contributors there proposed a plugin which allows grouping more launch configurations (possibly of different types) and start all of them with one mouse click.
Although the plugin functionality is limited, it does a great job. Source code is included so you can make changes as necessary. You will have to open it as a PDE project in your Eclipse and export it as a JAR, then place the JAR file in your Eclipse' plugins folder. A bit cumbersome but you do this only one time. After that restart your Eclipse and look for "Basic Workflow" in your launch configurations dialog.
Plugin source is available here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=39900#attach_177951

Categories

Resources