Suppose I extracted a Java project from a tar archive. How do I add it to Eclipse (Indigo)?
In the past when I have had to so something like this, I simply created a new Eclipse project with the same name and manually copied all the .java files into the proper folder down at workspace/projectName/src/topDomain/companyDomain/packageName.
Is there a better way?
File - Import... - Existing project into workspace.
This supposes that the tar archive contains the whole project, including the .project and .classpath files.
If it doesn't, then either make a new project where you want, and copy the source files, or create a project and specify that its location must be the directory containing the sources folder that you extracted from the tar.
Related
I have a Java project in Eclipse IDE for Enterprise Java Developers 2018-12 (4.10.0) built with Maven.
For some reason the folder src/test shows in Project Explorer as a "project folder" (by that I mean a Eclipse project folder, not a file system folder), besides being shown in the project as a source folder as well. That seems unnecessary and anomalous. For example, the same does not happen with src/main, which appears as a source folder only:
If I try to delete the project folder src/test, Eclipse warns me that it contains source folders which will be deleted along with it. I actually tried it anyway once: made a copy of the files, deleted the src/test project folder, and then replaced the files in the disk, but when I do that, the project folder just pops back.
Why is this happening and how can I clean it up?
src with its subfolder test is shown for reasons
There are regular and source folders. For faster access source folders are displayed compacted on the first level instead of in the regular folder tree. In your case, there are five source folders src/main/java, src/main/resources, src/test/java, src/test/resources and - probably by mistake (see below) - src/main which are not shown in the regular folder tree, but on the first level.
In contrast, src and its subfolder test are regular folders and therefore are shown (even if they are empty except for the source folders) in the regular folder tree. They are shown so they can be selected and the right-click menu can be shown containing commands (which might be contributed by additional installed plug-ins) related to selected folders only. Selecting all source folders contained in src is not the same as selecting the src folder, for instance when doing a file search on the selected folders, a .gitignore file in the src folder would otherwise be missed.
src/main should not be a source folder
To have src/main and its subfolder src/main/java as source folders do not make sense since they are nested. In your case, it is a Maven project so you can right-click the project folder and choose Maven > Update Projects... to derive the source vs. regular folders settings from the pom.xml file and overwrite the settings made manually. These settings are stored in the .classpath file. In Maven projects the .classpath file can be derived from the pom.xml file and therefore it is recommende not be shared or versioned.
I have dynamic web project in eclipse. I set my default output folders (my class files) to be in WebContent/WEB-INF/classes. I have another files in this folder like .properties and .xml files. The problem is when eclipse make clean or new compile or I dont know exactly but sometimes it delete all the files from this directory. Do u know how to set eclipse to delete only the class files and never touch the other ones?
put your .properties , .xml files in source folder of your web project and not in classes folder. doing this way, eclipse will directly copy those files from source folder to classes folder after a build.
I read (and sometimes write in) a .txt file in my java project and I'd like it to be copied in the eclipse output folder called "bin".
Can eclipse do it while compiling ?
My project is like :
Project
Bin
blabla.class
...
Src
blabla.java
...
MyFile.txt
Thanks !
I think you need to actually move the text file to a sub-directory - something like "resources" and add that "resources" directory as a source directory to the project - Project/Properties/Java Build Path/Source/Add Folder. That doesn't mean that everything in a source folder has to be compilable.
I don't think that you would have another option, because if you would add the root directory as source folder, eclipse would complain, that it cannot nest source folders. So you need an additional (re-)source folder here.
The solution is :
use Eclipse Classic 4.2.1
click on "add project 'YourProjectName' folder to build path" while creating a new project (in Source tab)
Doing the right Include/Eclude stuff to select which files you want to copy
What do you guys do, when you have huge project built with ant for instance, where the source folders are right bellow the root project folder, for building classpath from source files ?
Putting entire project as a source folder is nonsense.
Putting separate folders as source folders can't be done if they are part of the package hierarchy and the only thing I could think of, is to copy the source folders into a separate folder and add it then as source folder which is weird but I don't know how else to do it.
Having to duplicate sources just because of the eclipse way of making classpath and also because of somebody doing stupid project structure
It's really pain in the ass...because the ant scripts are written for this structure.
Even if it was just one folder, it's a problem anyway. There must be included the upper folder to the source classpath which means it is included with all the crap around and also it means that package explorer is flooded with the packages.
example:
Instead of /project/src/java/utils where we can put src folder into source classpath...
there is project/java/utils + lot of crap like /project/docs is in the project as well.
The trick is:
An Eclipse project root directory is defined by where the .project and .classpath are.
Two options here:
Those Eclipse project files are located in the workspace (and the 'project', the one with 'java/utils' inside, is not)
Then you can make a linked folder within the Eclipse project to reference 'project', calling that linked folder as 'src', using it as your source folder.
The ant script remains right where it originally is (in the 'project' directory, along with all the other sub-directories)
Those Eclipse project files are located directly within the 'project' directory (along with 'java' and 'docs': don't.
Delete that Eclipse project (not its content, only its definition, that will only remove the .eclipse and the .classpath), and recreate anywhere else.
Then go back to 1.
For each source folder in eclipse you can choose which subfolders of it you want to include or exclude as a source folder (you can also use patterns). If I understand correctly, in your situation you can add the project root folder as a source folder and include only those folders that contain source. So in your example only "java" would be included.
For me, both things are exactly the same. What's the point of these? Where's the difference between Project Folder and Source Folder?
The Project Folder is where the nbproject folder (Netbeans configuration for the project) is stored. The Source Folder is where your have all your stuff.
They can be different but you need to check the Put NetBeans metadata into a separate directory in the New Project wizard. Afterwards, it can't be changed.
The Project Folder will have have the build and dist folders in it along with the source folder. The source folder only contains your source code where the project folder hold the compiled classes, meta information, test cases, and distribution folder.