• 0

Need some basic help with Eclipse


Question

Anytime I have to work with Eclipse I feel like I've been removed a leg and half of my fingers : handicapped. And yet at some point I'll have to be comfortable with the IDE (ie: by this summer - I'll have to work in Java mainly).

So aside from putting you in context, I have a precise question.

I have a homework to do, in Java. It must be done on Linux because the provided code includes bash scripts and the like, but Eclipse looks the same to me on Linux and Windows. So anyway. There are four .java files that come in a zip file, they are classes and one is the program with a main method. I want to use that as my "project" in eclipse (like projects in Visual Studio) : be able to edit the files, add new ones, debug the thing, run the thing, etc.

Now I've messed around and got it somehow running but I know I wasn't doing everything as I should. I created a new project in the workspace, click-and-dragged the files into the package, and started editing them. At some point though I realised the changes I made weren't taken into account, and I was somehow editing copies of the files that were not part of the project. A few copy-pastes fixed the problem but heck, that's not too professional.

So please give me a basic tutorial on how to accomplish this.

There I'll give you some Java code :

// MainProgram.java

public class MainProgram
{
	public static void main(String[] args)
	{	
		HelloWorld.printMessage();
	}
}

// HelloWorld.java

public class HelloWorld
{
	public static void printMessage()
	{
		System.out.println("Hello World!");
	}
}

These are existing files, their name is indicated in comments. Please tell me step by step (I'm stupid, ok ?) how to compile and debug that code properly in Eclipse.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
How are you adding existing files into Eclipse, are you using the Import option from the Project panel?
Drag-and-drop from a folder.

I've figured it out a bit better now, when I create a project I select "from existing source" (something like that) and select the folder containing the files. And it works. But I've still quite a lot of difficulty. When I go to the debug view and launch a debug session, I can put breakpoints but they don't work (and they're hard to see, tiny blue dots in the margin); all the debug commands I'd like to use (Step into, step over, resume, etc.) are greyed out in the menu. Running in debug is basically just like running normally, don't know why. I know I got it working before though.

I'm also confused as to what gets run when I click run, as I divided my project in two parts by creating two different packages each with a class containing a main method. What I do now is right-click the right class in the package explorer and select run from there, but it feels messy. Should I rather create a new project for each different program?

Edited by Dr_Asik
Link to comment
Share on other sites

  • 0

Eclipse has multiple Run Configurations - just hit the drop-down arrow next to the Run icon and you can create & select from your run configs. To get the debug options you just need to run in debug mode (small spider icon to left of Run in the toolbar).

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.