Jump to content
  • Advertisement
RidiculousName

Java Managing .java Files in Eclipse

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Edited by Alberth
explained how to make use of packages in eclipse

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!