eclipse - folders for classes - eclipse

I have a android app in eclipse, and by the time I have more and more classes in it.
As you can see, its pretty messy.
In visual studio I know how to add sub folders in the project, and organize the classes in a more ordered way (for example Interfaces folder, Client folder etc).
How can I do it in eclipse without messing with the namespaces or causing any errors? do I add packages?
thanks!

Yes, you need to create package inside of "com.example.tremp" by right-clicking it.
I think it should have a name including the parent package name (e.g. "com.example.tremp.activities"), but I have tried naming it without parent package name (e.g. "activities") and it worked fine by me.

I think the only way is to create new packages and then assign each class to a package .

Related

Changed workplace in eclipse but can't run programs

Eclipse IDE
Today I decided to change my organisation method a little bit and decided to create projects for some exercises I was doing.
Let's say I had them in folder "Subjects" to which I creater a subfolder "SubjectA".
Problem:
After changing the workplace from Subjects to SubjectA I can't run my programs from the other subjects or anything outside SubjectA, is there a way to do it wihtouth having to import them to SubjectA ( as it wouldn't make sense)?
If not, do I have to keep changing the new java project location everytime I want to create a new one from different subjects (as I can't set my workplace to something more specific)?
Sorry for the silly question but I wasn't beeing able to find any similar ones.
I would suggest instead of using different workspace you can use different projects or packages.
In Java project, you can store all the information related to a specific project.
A java package is a group of similar types of classes, interfaces and sub-packages.
so you can either create multiple packages or projects like
Workspace
--------->Project 1->src
. ------>com.package.one
------>com.package.two
or you can do something like
Workspace
---------->Project1
---------->Project2

How to show shortened project names in the Eclipse package explorer?

I work for a big company that has standards on Java project names. Long standards:
com.company.department.subdepartment.stream.project
Rather than let the package explorer take up a sizable portion of my screen, I'm looking for a way to shorten the project names. Mousing over project names shows the full name, but it's still very slow to determine which project I want to look at next with the incredibly long names. As has been answered before, package names can be shortened. I've got a rule set up, but it only works for packages:
com.company.department.subdepartment={department}
Is there a way to do an analogous thing for project names in Eclipse?
Package explorer uses the org.eclipse.jdt.internal.ui.packageview.PackageExplorerLabelProvider class to provide the view labels. Going through the source of this I don't see any support for shortening the project names.
The following ideas depend on how your eclipse workspaces are setup. If you're lucky and you just import project from your VCS, these could work for you.
If you're using maven, Eclipse project names are usually derived from your GAV. The Import as Maven project wizard has options for what pattern to use for the project name based on your maven GAV.
Otherwise, you can sometimes just right click the project -> rename. YMMV if you have any scripts or such that have the project name hardcoded. If you have these constraints, find those scripts and use variables rather than hardcoding.

NetBeans importing classes package problems

I have created a class in Java that I need to import into NetBeans and use in a GUI. What I have done so far is add the jar file containing the classes to the library in my project. I can look inside the jar file and see the classes I need inside the . I have looked around online and know that the best to way import these classes is to move them to another package that isn't the .
My problem is that I do not know how to do this. I saw that I can create a package in netbeans, but it is gray when it appears and I can't seem to do anything with it. I basically have no idea how to create packages that I can use to import classes If someone could please walk me through step by step I would greatly appreciate it. I have looked at the other posts on this site and other places online, but they seem to skip over somethings I am not sure about. My teacher didn't mention anything about packages either, so I am really in the dark.
You can copy your source files (*.java) in your project's src folder, then use refactoring to change the package.
Right-click your java file, then select Refactor > Move and type your new package name.

How to link two or more projects in Eclipse?

I am trying to develop my application in different Eclipse Java projects where each will contain a certain feature. Then I want to combine them in one complete Java project.
However, I have a problem when linking the sources.
The sub-projects can correctly refer to parent-project classes but some of the source files that are accessed by the parent projects cannot be identified in the sub-projects.
I have a workspace/ParentProject/src/main/resources/file, where in the ParentProject I am accessing with "src\main\resources\" from within Java.
However, at runtime the ChildProject throws an exception that they cannot access the file : 'file:/E:/Eclipse%20workspace/ChildProject/src/main/resources/file'
So, when using a method of the ParentProject from the ChildProject, the classpath is somewhat transfered to the ChildProject. My question is how to resolve this.
I hope I made it clear what the problem is and will be really appreciative for any help.
Regards,
Petar
Btw: It is explained there How to link project in eclipse but I still have the error, that the child project cannot access resources accessed by the parent project.
Although I am not entirely sure what you need to do, it sounds to me that you are trying to create circular dependencies, which is an anti-pattern. You want to avoid creating dependencies where project a depends on project b, but project b also depends on project a. If you provide more details on your use case and what you are trying to create I will be happy to provide some guidance as to how you could structure your dependencies.
Hope this helps.
Right click the Parent project and click properties. Then click Java Build Path on the left hand side. Next click the projects tab. Make sure the Child project is selected as a required project, if it is not Add the Child project.
You should also do this for the Parent Project.

How to create .jar from specific package (without main) in Netbeans?

There are a lot of similar questions, but none for this specifically. I have a Netbeans project with a bunch of packages. Only one has Main. I'd like to be able to create a .jar from just one of the packages (and all the classes it contains, of course), which doesn't have main.
Is this feasible without having to put that package in another project or without having to screw around with build.xml? If the latter, any easy way or good rtfm links?
The point is i'm developing part of an application for college, each group member is developing a module of sorts. If each could provide their .jar the main project can just include jars and use them. I'm guessing all the mains in the jars wouldn't really hurt? But still...
You can use the project properties to customize your project's jar file content. This screenshot shows what it looks like for a Java Class Library project.