Eclipse running previous program - eclipse

It is a new problem. I copy paste a program and try to run it in eclipse. But the eclipse keeps running an older program. I have no idea what is going on. ( I saved the program as someone on the internet suggested) In the run button, there are only old programs. So I goes into the run configuration option and double clicked the java application option and somehow the one I am working on right now appeared. And I am able to compile and run the current one. So technically I solved the problem, but I would like an explanation, what was going on?

What is going on here is how Eclipse decides what to Run when you press the Run button. My suspicion is you have settings which are causing it to launch the last launched item, rather than something new that does not have a launch configuration. If you hover over the Run icon, it will show the name of the launch configuration that Eclipse will launch.
For a new program, you want to do a Run As -> Java Application (From Run menu).
To configure the default launching behaviour, see Preferences -> Run/Debug -> Launching, and then set the options you want in the Launch Operation group.

It just copies path of the server from old project.
It has the TWO solutions :
1) you can simply click on your Tomcat->Modules (Web Modules)-> Edit
And simply change the path with you project name or just put "/".
OR
2) You can right click on your project -> Properties-> Web Prjoect Settings
edit Context root, just simply put "/"
Thank you

I run into the same problem (I am new in java). I solved the problem by * I ensure did not use the defaul package . Step 1. Create java application. Step 2. Create package (stay away from default package). Step3. Create a class that will have my getters and setters (example:
package revature;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s = new Student();
s.setName("vijaiy");;
//getting value of the member
System.out.println(s.getName());
}
}
Step 4. Create the main class to run the program
Example:
package revature;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s = new Student();
s.setName("vijaiy");;
//getting value of the member
System.out.println(s.getName());
}
}
My problem was that I did not set up my brain to think 'java', I was thinking on 'javascript'.

Exit out of eclipse, then open Eclipse in a new Workspace and create a new Project. This is a quick solution if you are willing to have multiple workspaces.

Related

get all the classes with main method in Eclipse Java project

I'm working on an Eclipse plugin to help people manage their project.
Is there a way to list all the classes with the main method under a project by Java code?
I think the best practise is to use only keyboard.
Create new java class with Ctrl+n
on dialog box, enter its (class) name
use (left)Alt+v to easily tick checkbox for - public static void main(String[] args)
then press [enter] Finish and voila class is ready

Eclipse Luna version 4.4.2 not showing suggestions for java 8

I recently installed Java 8 64 bit version on my machine and installed Eclipse Luna version 4.4.2 64 bit.However when I programme a java application,the IDE not showing auto suggestions to use Java 8 features like use lambda expressions instead of anonymous inner class.The code I have used is given below.As my reputation is low I am not able to post images.
public static void main(String[] args) {
Thread t=new Thread(new Runnable() {
#Override
public void run() {
System.out.println("Run method called");
}
});
t.start();
}
Works fine for me in Eclipse Luna 4.4.2. I press Ctrl+1 when staying on new Runnable:
Seems that there's no way to mark it as warning (yellow lightbulb). However you can switch on a save action for lambda. Go to Preferences -> Java -> Editor -> Save Actions, check "Additional actions", press "Configure", go to "Code style" tab and check the "Convert functional interface instances":
This way all the anonymous classes which can be converted to lambdas will be converted automatically upon you press Ctrl+S. You can also make this conversion for the whole project at once: select the project in Package explorer, right-click, Source, Clean up, Use custom profile, configure and check the same checkbox.

Access Active Editor from Eclipse Launch Delegate

I am developing an interpreter for a visual programming language that I am implementing using Eclipse, EMF and GEF. I am currently creating an interpreter for the diagrams.
To execute a diagram, I decided to implement a launcher configuration. When the configuration is executed I want to read the EMF model from the active editor and interpret it. The problem I have is that the active editor can only be accessed from the UI thread, and I don't want the interpreter to execute in the UI tread since it may be a long process. This is the code that works but should not be used:
#Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
OPMGraphicalEditor editor = (OPMGraphicalEditor) activeEditor;
OPMObjectProcessDiagram opd = editor.getOPD();
Interpreter.INSTANCE.interpret(opd);
}
});
}
I'm sure there is a proper way to do this, but I haven't found it. The examples for launch configurations that I found in the internet use external programs, but I am (currently) implementing my interpreter as part of the workbench.
Thanks for the help.
You can use the above code with a ...getDisplay().syncExec(...) instead and then store the pointer to the editor into some enclosing object.
If you're launching your configuration from the editor directly (right-click, run as..) then you can just use an ILaunchShortcut and overwrite its void launch(IEditorPart editor, String mode) method to access the editor where the file is launched from.

In Eclipse, how to close the open files(editors) when exiting without auto-load in next startup

a problem troubled me for several days. Would like to find the answer here... Thanks ahead!
I developed a plugin in Eclipse. When it starts up, it will open the files (with specific editors we developed) left at the last exiting. I wonder whether I can disable this auto-starting in code?
BTW, I have tried the option "Window->Preferences->General->Editors->Close editors automatically", however, with useless result.
Thanks for your advices!
Have you tried the 'Restore editor state on statup'?
If you're already creating your own WorkbenchAdvisor (if you're creating an RCP application), you have access to the workbench configurer which can change this property:
public void initialize (IWorkbenchConfigurer configurer) {
super.initialize (configurer);
getWorkbenchConfigurer ().setSaveAndRestore (false);
}
For a non-RCP application (ie: just a plugin), it's not recommended to do this since it is a global setting that will affect all editors. It can still be done though:
public void disableReopenEditors () {
String pref = org.eclipse.ui.IWorkbenchPreferenceConstants.CLOSE_EDITORS_ON_EXIT;
PlatformUI.getPreferenceStore().setValue(pref, true);
}
If you want to do it manually, you can follow Where does Eclipse save the list of files to open on startup? to delete the file the workbench uses to store this information.

How do I associate a file with a perspective in an eclipse plugin

I have created an editor plug-in for eclipse that is associated with the file extension .eap
I have also created a perspective that contains views for this data.
I would like to add the following behaviour: When I double click on the .eap file I'd like the EAP Perspective to be opened.
Just like what happens when you click on a Java file for the first time.
Any help appreciated!
Will
try {
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.showPerspective(EapPerspective.ID,
workbench.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
As far as I know, clicking on or opening a Java file for the first time will not open the Java perspective. However, perhaps you are thinking about how after using the New Java Class Wizard, you are prompted to change to the Java perspective.
Regardless, there are several things that you can do:
In the org.eclipse.ui.newWizards extension point, specify the finalPerspective as well as preferredPerspectives
Assuming that you have sub-classed AbstractTextEditor, then override the setFocus() method and add some logic to change to the appropriate perspective, something like this (but be careful to add specific null checks):
getEditorSite().getWorkbenchWindow().getWorkbench().showPerspective(desc.getId(),
getWindow(), pageInput);
The first solution is recommended, although it will not cover all the cases that you are asking for, and the second is a bit naughty as it goes against Eclipse conventions.