Why I have to go to run configuration in Eclipse, everytime? - java

I wrote two java projects which are purely independent.
When I run the first project "aa", automatically a "Run Configurations" window appeared, and I chose "cc" (cc.java) under Java Application tab.
The app run.
but when I made another java project "dd" and wrote code in its class "ff", The run button showed the output of cc.java in console.
I had to go to "Run Configurations", and select "ff" (ff.java) under Java Application tab.
Why I have to to do this everytime?
What if I have multiple classes under one project?
Is there anyway to run a project by simply clicking run button?
Regards,
BAQAR RAZA MANGRANI
Struggling programmer.

As far as I know, if you have several classes including a main method in eclipse, as soon as you run them once, they appear as shortcuts when expanding the run button(or debug). Just click on the small arrow next to the start button and select the file you want to run.

Related

Eclipse problem : the selection can not be launched, and there are no recent launches

I am a newbie with Java and trying to write a very simple program like this ofcourse
public class FirstProg {
public static void main( String[] args) {
System.out.println(" I am learning how to code");
System.out.println("Today's date is");
}}
When I ran it, it said to me that, the selection can not be launched, and there are no recent launches , I ran it on Eclipse. Could you please give me some ideas? I am a newbie and very confuse with this problem. Thank you very much.
It is difficult to be exact, because we don't know exactly what you've clicked on, or what version of eclipse you have. Eclipse is very flexible, and one result of that is that it does not have the same subwindows and buttons for every user.
There is a standard 'view', i.e., a subwindow within Eclipse's main window, called "Project Explorer. It is most often on the left side of the eclipse window, and displays folders and files in one or more projects.
Find the folder for your project in that view, right-click on it, and look for the options "Run As..." and "Debug As...". Those are also menus, they will have options that depend on how your eclipse is configured. But one of the options should be "Java Application", which is the right one for what you're doing. "Run As..." runs your program; "Debug As" runs it under the eclipse debugger.
If there is only one Java class in the project with a main(String[] args) method, then eclipse will run that class. If there's more than one such class, it will ask you to choose.
Once you've done this, there are usually buttons on the top of eclipse; one is an insect-looking icon, the the other a triangle with a point to the right -- the first is 'debug', the second is 'run', and once you have debugged or run a class, clicking on one of those will debug or run the last class you debugged or ran.
Good luck.

Running Projects in IntelliJ

I've got a project from my teacher, in which i should add my implementation for a certain aspect.
The Project already got a main method but still the "Run" and "Debug" buttons in the top right corner are greyed out.
I've also tried right clicking the main method and java file, but it doesnt show me run or debug.
Also tried using the "Make Project" Button (top right corner), but it doesnt let me run it either.
How can i run the project?
Help would be much appreciated cause I cant seem to find a solution...
the "run" and "debug"-button in the top run the currently selected main-method. As long as you haven't selected one, you can't run it. In the current version on the left side of the editor-pane, there should be a green arrow right next to the main-button. Run it once via clicking that arrow and from that point on you can run/debug the program using the buttons on the top-window.
In this image you can see the green arrows (version 2016.2.4).
Alternatively, you can use the following more complicated, but also more versatile option:
Directly from the run- and debug-buttons is a button that toggles a list. In the initial configuration of the project, this list contains exactly one Item: "Edit Configurations...". Use it to create a custom-target - go for Application, if your using a java-class as entry-point - and set up the configuration as you wish. Clicking the arrow mentioned earlier does basically the same with a bit of automatic configuration.
Third alternative:
Open the context-menu on the main-method. It as well contains options to run and debug the program with the marked method as entry-point. Works for the context-menu of the respective class as well.
You have to add a run configuration. Do this with clicking the grey button and then clicking at sth with configurations (i am not in front of my PC), then add there the config
Does your main method have the proper syntax for arguments? I found that in Eclipse, the program will not let you run the main method if it is not in the format of public static void main(String[] args). Also, does your code compile properly and your IDE just doesn't let you run it?

Eclipse Sample action set button missing while developing plugin

OS: Windows 7 x64; Eclipse IDE for Java Developers (Juno SR2)
I am following tutorial from a book for devlelopment of Eclispe plugins. At one point I made a mistake so I decided to delete whole project (I selected "Delete project content on disk (cannot be undone)"). So I started fresh. But then, after just few initail steps: File -> New -> Other -> (Wizard) Plug-in Project, Next, Next, selection of Hello, World template, -> Finish when I run project it was supposed to get button on the toolbar when Testing -> Launch an Eclipse application is executed.
But this time there was no buton at all (Eclipse launches new instance of Eclispe). Also, I couldn't find it in Customize Perspective -> Choose which tool bar item to display (it should be under Sample Action Set).
After few failures, including erasing "runtime-EclipseApplication" folder on disk, I created new project, named just "Hello World", and this time it works OK, the is buton on toolbar, and there is item "Sample Action Set" in Customize perspective, and there is even "Sample Manu" on Menu Bar. Now, even if I start HelloWorldProject it also has a button and menu item etc., i.e. it works as it should.
But, if I now delete HelloWorld, then even HelloWorldPlugin reverts back (!) and now (when test instance Runtime WorkBench is started) it again don't have button and menu bar?
What gone wrong and how should I fix it? I mean this is just an example, I can just go on with another project name, but in real production environmet if I have strict specification I can't get out so easily, and that is why I would like to know what happend and how to fix it?
I found how to fix it, but I still don't know why it happened on the first place and especially why it persisted, even after several complete deletes of project?
The fix is: Run -> Run Configuartions ->Plug-ins tab -> Workspace -> (select) HelloWorldPlugin.

How can I easily run different configurations in Eclipse?

I have an Java applications which I would like to run with different values of input parameters (specified in the command line). In "Run -> Run Configurations" I have created different configurations corresponding to different values of the input arguments.
I can run these configurations in the same way (throw "Run -> Run Configurations"). But in these case I have to perform to many actions (clicks) to run a particular configuration. Is there a easier (faster) way to do that? For example I expect that I can do it throw "Run -> Run as" but in the drop-dawn menu of the "Run as" I see "(Not Applicable)".
In the toolbar, the Run icon, has a small arrow pointing down. That gives you a list of recent runs with corresponding configurations. This still takes a number of clicks.
I have not been able to figure out how to (if possible) add shortcuts or keybindings to a particular run
Once you have run a particular configuration once (by going through the Run Configurations window) that configuration should show up in the list of run configuration history, so you can just select the drop down arrow and choose that configuration.
Or choose organize favourites and add your configurations. These should then show up in the drop down list.

Launching an SWT window/process from an RCP app

Ok, I have a(n) RCP application (that I didn't write), and an application I've developed using just SWT. What I want to do is basically import and launch the main method of the SWT application with arguments, such that it runs in another window, like it's another process. The argument I want to pass is a complex data structure that I don't want to serialize.
I originally thought I could just design my SWT app to be a library and import it, have it spawn its shell, etc. But I neglected to think about how the SWT app's main loop has to run on the main thread, which seems problematic.
So I started looking into integrating it with the eclipse plugin architecture. Problem: I don't know anything about the eclipse plugin architecture or RCP, and when I try to learn, I run into an inscrutable wall of things that are totally unlike what I want to do (ie building new buttons onto the eclipse workbench). How do I get started developing a plugin that just launches another window?
You will need some kind of button to launch your application so just must hook into the Eclipse menu system.
Try:
1) In Eclipse, File -> New Project-> Plug-in project
2) Make sure you check "This plug-in will make contributions to the ui"
3) Uncheck "generate activator" since you won't be needing it
4) Select "Hello World command" from the code template
Now you will have a sample handler and a method called execute where you could call your SWT-application with the display you're using in the RCP-application. If you really must call void main(String[] args) you could get the display by calling Display.getDefault(), which will either create a new display or use the one from the RCP-application.
You will also have to modify the plugin.xml file so it points to the correct menu in your RCP-application. If you want your launch command to be in the file menu etc.
Finally, right-click on your project and select Export -> Plug-in Development and create a jar-file where you launcher will be in. Drop that jar into the plugins folder of the RCP-application and you should be able to launch the SWT-application from the command you've just created.
There will probably be a couple of bumps on the way, but that's roughly what you will have to do.

Categories