Managing .java Files in Eclipse

Started by
3 comments, last by xexuxjy 5 years, 5 months ago

I have a project with a bunch of different .java files. Is there a way for me to organize them in eclipse while still allowing them to access each other?

If I split the project in different folders, Eclipse can't find the different files when they're called in a different file.

Advertisement

A package is a folder (in 'src', in Eclipse) that Java understand, so that's one way to organize code. https://docs.oracle.com/javase/tutorial/java/package/index.html explains packages (if you don't know that site, its tutorial is very accessible, recommended reading material for learning Java).

EDIT: To make a package in the project explorer, RMB on 'src' in a Java project -> New -> Package. Add Java files by RMB on a package -> New -> Java file. Drag/drop of Java files to other packages starts a refactor to move the Java file, and fix all its references (in the opened projects).

 

At a possibly much larger scale, Eclipse has a plugin system that you can use. In fact, that's how they built entire Eclipse. A plugin is its unit. It's a piece of functionality, coded in Java, and (typically) stored in a Jar file. It offers some services for other plugins, and uses services of other plugins. This provide / use relation creates a dependency tree. Plugins are otherwise self-contained. A piece of software like Equinox manages the plugins and its dependencies. Equinox also connects service providers with service users. An editor for a language could be a plugin.

Assuming you have your Java source files in nested folders that correspond to the respective packages (as declared in the package statement in each file) what you can organize is the location of these package folders: Eclipse looks for them in the Eclipse project source directories, which are set in the project properties. You can add multiple locations (for example, one for the main code and one for tests) and exclusions.

Omae Wa Mou Shindeiru

You can also have multiple eclipse java projects and have some projects reliant on other ones, which can be a good way of structuring things as well. 

This topic is closed to new replies.

Advertisement