Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a folder in Eclipse?

Tags:

java

eclipse

I'd like to create a folder under a package in Eclipse... The purpose of this folder is merely for organizational purposes. Meaning, I don't want it to be another package. Every time I try to add a folder under a package, it just creates a package instead. I'd like to have the following structure:

project/src/package1/someClass.java
project/src/package1/someFOLDER/anotherClass.java
project/src/package1/package2/anotherFOLDER/oneOtherClass.java

Is it possible to do this without adding a package? I come from a .NET/C# and C++ background... here I'd just add a folder and the reference to that class would be updated in the project.

How can I just add an organizational folder in eclipse? Thanks

like image 352
Polaris878 Avatar asked Mar 26 '10 00:03

Polaris878


People also ask

What is folder in Eclipse?

Whenever you make a project inside of Eclipse, Eclipse will auto-magically create a new folder in your workspace with the same name. Inside of that folder it will create two folders: bin, and src (source). The bin folder can be ignored. This is nothing more than the folder in which Eclipse stores the .


2 Answers

Actually, folders are packages in Java so your question doesn't really make any sense in a Java context.

The term 'package' might be misleading... a package is definitely not the same as an assembly in .NET. You can think of 'package' more as a namespace, which in the Java world happens to be determined by the directory path.

For non-source files, you can create a new folder outside of your source folder, it will then be treated just like any other folder and not a package.

like image 183
Martin Avatar answered Sep 29 '22 06:09

Martin


WTF are you supposed to do when you need multiple classes to be package private in a large project? Just look at your 25-30 class files all in the same directory?

That is a problem with Java's package system. Every package is a directory, and sub-packages are just different packages (no special visibility rules).

The most coarse visibility level is package-private, so that, yes, you have to lump your 25-30 files into the same package to avoid universally public visibility.

OSGi addresses this issue by introducing bundles, which can choose to not make packages visible to the outside. This gives you "project-private" packages.

Update: Also, you can reduce the number of files by putting related classes into the same source file. Only public classes need to have their own source file (I do prefer to have one file per class, though, public or not).

like image 22
Thilo Avatar answered Sep 29 '22 05:09

Thilo