Multiple java output directories in Eclipse/RAD? - eclipse

I'm using RAD (which is based on Eclipse) and I have two source folders in a project, one for the core source files, and one the tests. How can I have them compile to different output (bin) folders?
Obviously I don't want my unit tests to be built into my output jar.

First check the Allow output folders for source folders box, then modify the individual Output folder elements under each source directory.
Solution discovered on EclipseZone

Right click on the projects, select Properties, then Java Build Path. On the tab "source" you see your source folders. Enable the checkbox "Allow output folders for source folders" and configure each of your source folder appropriate.

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 place a file on classpath in Eclipse?

As this documentation says, "For example if you place this jndi.properties file on your classpath", but how can I place the .properties file on my classpath if I am using Eclipse?
Just to add. If you right-click on an eclipse project and select Properties, select the Java Build Path link on the left. Then select the Source Tab. You'll see a list of all the java source folders. You can even add your own. By default the {project}/src folder is the classpath folder.
One option is to place your properties file in the src/ directory of your project. This will copy it to the "classes" (along with your .class files) at build time. I often do this for web projects.
This might not be the most useful answer, more of an addendum, but the above answer (from greenkode) confused me for all of 10 seconds.
"Add Folder" only lets you see folders that are the sub-folders of the project whose build path you are looking at.
The "Link Source" button in the above image would be called "Add External Folder" in an ideal world.
I had to make a properties file that is to be shared between multiple projects, and by keeping the properties file in an external folder, I am able to have only one, instead of having a copy in each project.
Well one of the option is to goto your workspace, your project folder, then bin copy and paste the log4j properites file.
it would be better to paste the file also in source folder.
Now you may want to know from where to get this file, download smslib, then extract it, then smslib->misc->log4j sample configuration -> log4j here you go.
This what helped,me so just wanted to know.
Copy the file into your src folder. Go to the Project Explorer in Eclipse, Right-click on your project, and click on "Refresh". The file should appear on the Project Explorer pane as well.

IntelliJ equivalent of "Inclusion and Exclusion Patterns"?

I have an Eclipse project where the Java build path is defined (in the project properties) to contain the folder "src" with certain inclusion patterns ("com/example/package1/**", "com/example/package3/**"). The reason is that, say, "package2" contains things that are irrelevant to this project but are relevant to some other project that shares its source tree.
I would like to try to use IntelliJ IDEA, but I can't seem to find the equivalent feature. Does it exist, or is there another way to do what I want?
Under a content root you can
-Include source folders (The folders containing the com package) with the blue folder button.
-Exclude folders with the red folder button. It will completely remove files from the intellij eyes. Not just to the java compiler.
-If this is not enough you have /setting/compiler/exclude where you can exclude packages or files individually but only to the compiler eyes. You can quickly add a file to these excludes by right clicking on a java compilation error. It may also work for compilers other than the java one.
In the Project Structure window, under the Modules section, Sources tab, you can mark some directories as "excluded" by selecting it and clicking on the "red folder" button.
Have a look at Preferences…/File Types/Ignored files and folders
This applies to all projects though.

Eclipse: Linking source located in multiple subfolders of given folder

I need to add external source code into my Eclipse project.
Project Properties>Java Build Path>"Link Source..." seems to be appropriate.
But it is necessary to add all the "source" folders of the folder that I link. It is a very complicated Folder structure, where "source" folders are located in different parent folders, but form the entire source code together.
I just hate the idea to manually navigate to every folder and add it. "Inclusion patterns" feature in eclipse seems to be suitable for the task, but I can't get its syntax and how to specify inclusion to add all "source" subfolders.

setting source classpath in eclipse with stupid project structure

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.