I've been searching the net and I can't seem to find any directions so I can set up eclipse to compile java. It seems I have to do 4 things every time I want to compile when I should just be able to click the run button.
Now I'm having to change the configuration every time I compile the java source I'm looking at and currently editing. This makes sense since the project needs to know which main to use but is there a way to set it up to compile the source file I'm looking at? Or will I need to create a new configuration for each class that has a main?
David Newton wrote:You're going to have to be more specific; normally a project would only have a single main.
If you have a project with many main methods, create new configs rather than changing the existing one.
okay. To be specific, the reason I have so many main methods is because I'm working through a book learning a new api and coding the examples. It's tedious but if this is the only way so be it.
Actually, it's not that uncommon for a project to have multiple main methods. I know a number of people who set up projects with test code and it's run by running the class under test as a main class. Although JUnit is what I recommend - it allows better management of tests and provides a better supporting framework.
Eclipse is based on the concept of a Project. A Project doesn't have to be a directory inside an Eclipse workspace, but that's a convenient (and default) place to put them. Technically, the Project is a set of project definition files + workspace metadata, but we usually consider the directory containing the actual code and supporting files to be the "real" project. In order to keep things manageable, each Eclipse project must have a single root directory, although projects may "borrow" resources from other projects.
When an Eclipse project has been defined as a Java project, one or more directories are designated as Java Source Code directories, and one or more directories as compiled class directories. This can be adjusting using the Project Properties editor. Whenever you save changes to a Java Source Code file, it's automatically recompiled (unless you switch off that option) and the resulting class file gets placed under that source file's corresponding output class directory.
Running apps and debug sessions is actually done in a separate subsystem. You define a Run profile and specify not only the Main class, but any other environmental options you might need, such as classpath extensions, command-line options and so forth. It's really just the GUI equivalent of setting up batch execution files. You can set up as many different run profiles as you want (the same profiles can be used for both run and debug). It's also permissible to set up more than one profile for a given class. For example, if you want to test using a different set of run command-line options.
Run profiles also apply to other environments besides stand-alone Java applications, but the details vary, based on the environment. For example, the Applet run profiles invoke an Applet Runner.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
the reason I have so many main methods is because I'm working through a book learning a new api and coding the examples.
Try this. Create a single empty Java project. Then when you need to create a new class for the next example, use Eclipse to create the class within that project. You can run the example either from a command line or within Eclipse by right-clicking the class and selecting Run As | Java Application.