Ignore SVN files when exporting a WAR file from Eclipse? - eclipse

I have a Dynamic Web Project in Eclipse. I can pack it to a WAR by right-clicking the project and choosing Export > WAR File. This creates the WAR file as expected and it works.
The problem is that Eclipse includes all the .svn folders of the project into the WAR file.
Is there a way to tell Eclipse to ignore .svn folders in the WAR exporting process? Or even better, tell it to ignore all files or folders that match some given regular expression?

Enter the project properties > Resource > Resource Filters > Add... > Exclude All > Files and Folders > All children (recursive) > Name matches *.svn > OK.
All .svn files and folders will be ignored, including when you export WAR files.

This seems to be documented in bug 182534 (2007! And still opened).
A custom separate ant script would be needed for now in order to build the exact war.
The internal "Export War" eclipse feature is not yet good enough for this scenario.

Installing the Subclipse plugin will make Eclipse aware of the SVN folders.
This also includes ignoring them in a WAR export.

You could use an svn client to do the trick. For example TortoiseSVN let you export a directory without .svn folders and files.
So what you could do is:
Export you war
Unzip it (a war is a zip file with changed extension)
Tortoise-export the directory (remember to check "Include unversioned files" cause your .class will probably be unversioned)
Zip the new directory and rename it to .war
This is not a good workaround but it saves you from checking every subfolder in your war to see if some .svn has not been removed.

While exporting the project just uncheck the unneeded folder like ".svn" in the Project Export wizard like this

Related

Eclipse project shows an unnecessary project folder that cannot be removed

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.

How to delete only class files with eclipse?

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.

Should renaming a project in Eclipse also rename project folder on file system?

Should renaming a project in Eclipse also rename project folder on file system ?
My project file system name remains the same even when I rename the file on Eclipse.
Should I manually rename the project on the file system to same on Eclipse ?
It appears that renaming a project will only rename the underlying filesystem directory if the project was created with the "Use Default Location" checkbox selected (meaning the project is created in the workspace directory). If you create a project and specify a custom location outside the workspace, renaming that project in Eclipse does not rename the project's host directory. In that case, you'll probably want to:
Rename the project in Eclipse (which will update any internal references and the .project file)
Remove the project from your Eclipse Workbench view (making sure that the "Delete file contents" option is NOT selected in the delete confirmation dialog).
Rename the project's directory in your filesystem.
Import the project back into your Eclipse workspace.
I was surprised to learn this (I tested it with Eclipse 3.7), but it seems to be logical to me. The idea is that projects in the workspace folder are considered to be "under Eclipse control" as opposed to projects that are located in arbitrary places on your filesystem.
Use Refactor to rename the project name. It will rename the file/folder in filesystem as well.
Menu -> Refactor -> Move... (Shift + Alt + V).
In this window you can change name of the folder name and also change the path completely.
If the folder name is important, then change it manually. Keep in mind that you will have to re-open or re-import the the project into eclipse. After you rename the folder, Eclipse won't know where to find it.
In Eclipse Oxygen (4.7) the Move option is greyed and renaming the project does not rename the directory. However, if you switch to the Navigator view (may need to find it under Window > Show View > Navigator) the Move option will be available and it will rename the project's directory.
This is a lot faster than having to recreate the project or re-import it.
If your project is a Maven project to rename, do steps as followed:
Open Context Menu on your project > Refactor > Rename Maven Artifact.
Change Group or ID.
Check "Rename Eclipse project in Workspace".
press OK button.
Update maven project by Context Menu > Maven > Update Project.
Using eclipse Neon 4.6.3, renaming does not work. You will have to do what E-Ritz said in his answer.
It is also worth mentioning that if you are importing a project as a Maven project (via Import... -> Existing Maven Projects), the project name will be taken from the pom.xml rather than the folder. So you should also change the <name>my-project-name</name> part of the pom

Add a restored Java project to Eclipse?

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.

How can I clone an Eclipse installation between computers?

How can I clone all of my Eclipse settings (preferences, plugins, etc) from one computer to another?
IIRC, Eclipse installs into a folder as opposed to all over the place like most Windows apps. Have you tried just copying the entire folder?
They are stored in the .metadata directory in your designated workspace directory. So you can copy that over, although some settings may not work right away as they contain absolute paths.
If you are referring to the plugins themselves, just copy the eclipse_dir/plugins folder
Eclipse has an import/export facility for general workspace Preferences:
File > Export > Preferences
Choose "Export All" and then provide a destination path and filename for your preference file (Eclipse will automatically add a .epf extension).
In a new (or existing) installation of Eclipse import the .epf file
File > Import > Preferences
Project specific settings, if you enabled (and configured these), are stored in the subfolders .classpath, .project and .settings inside the project folder. Assuming you preserve your project folders for use by the new Eclipse installation, your project-specific settings will remain safe.
Eclipse projects are also imported/exported via Eclipse file menu:
File > Import > File System
see this post regarding the way Eclipse uses the workspace .metadata directory