Make Eclipse copy source files in output folders - eclipse

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

Related

Property file not available in bin folder while building in Eclipse

I have a Project that I have built on Eclipse. I have a property file added in the src directory. The java class file is available in bin, but the property file is not available. Where am I going wrong?
Assuming the type of project is Java Project
Right click on the project and select properties option. Check in the Java build path all files under source folder are included or not and also check if some files are excluded.
In my case property file is being copied to bin folder. See the picture below.
Hierarchy of source folder and bin folder are same in my case.
If project is of type plugin project
Open the Manifest.mf file in Plugin Manifest editor and go to Build tab. Check the property file is selected here if NOT then select the file and check.
Edit:
Troubleshooting steps:
Simply Restart eclipse and completely clean and build the workspace and check.

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.

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.

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.

What's the difference between Project Folder and Source Folder in Netbeans?

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.