Eclipse: How to overwrite resources in src folder - eclipse

I have a program that alters a file in my src/resources folder, but the file that gets selected is in the bin/resources directory. How can I tell Eclipse to modify the file in the src/ directory. I understand that the bytecode is executed from the bin/ directory and the file needs to be visible to that folder, but I would like to know if it is possible to reference the src/ file.
I am using:
File file = new File(MyClass.class.getResource("resources/test.xml").getPath());
to load my file, but I don't want the path to my bin/ directory.
The path is:
/C:/Users/Foo/workspace/MyProject/bin/resources/test.xml

If you add src/resources to Eclipse Build Path, the compiler will then copy the entire folder structure to your output directory (i.e. bin) in which case you refer to test.xml using the same code:
File file = new File(MyClass.class.getResource("resources/test.xml").getPath());

Related

How to get current folder basename in vscode tasks and launch file?

I wanna make a C++ program that will all of its code into the an executable file with the current folder name. And this is because I wanna make a project like thing. And the project name is the current folder name and that's why I want the executable to be named with the current folder. But ${fileDirname} variable prints the whole path instead of the basename of the folder. Of course, I can use make file to build them, but the lauch file requires the executable file name, and I can't put the folder name there. And I don't want to change this launch.json for every project. Please help me!!

Eclipse plug-in: Specifying the output folder for an included file

I'm trying to export a plug-in into a jar. In this jar file I would like to include an extra file placed in the bin\com.example.myapp. This file is generated during compilation, but it's not copied automatically into the jar file when exporting the plug-in.
To include the file I selected the file in the Build Configuration tab for plugin.xml file. Thus, the following build.properties is created:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
bin/com/example/myapp/myfile.bin
jre.compilation.profile = JavaSE-1.7
This works partially, because even though myfile.bin is included into the exported jar file, it is placed in "bin/com/example/myapp/myfile.bin" whereas I would like to be placed as "com/example/myapp/myfile.bin", without the initial "bin" folder. Is there a way to achieve that result?
You can change the bin output folder but I think it will apply to ALL files, not just one :
Right click on your project and select Properties. And then click on Java Build Path. On the right side you can see the tabs Source, Projects, Libraries,...
Click on Source. Check the Default output folder:. There you can browse and select the different folder you want.

when I try to paste jar files in lib folder (in eclipse) it gives the following error :

when I try to paste jar files in lib folder (in eclipse) it gives the following error : cannot paste the clipboard contents into the selected elements.
You cannot paste a .jar file directly until and unless jar files are extracted. Instead do this,
Project -> properties -> Java build path -> libraries -> add external jars
Firstly do not paste the jars from a ZIP folder. Extract it and then copy and try pasting. It won't give cannot copy clipboard contents into selected elements then.
Try moving all the JAR contents outside the zip folder that you have just downloaded and then copy all the contents to the specified folder of your eclipse project

Make Eclipse copy source files in output folders

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

Eclipse clean removes my config file

In my Eclipse Java Build Path, I set Source Output Folders to:
WEB-INF/classes
and I put the config file globals.conf in this folder.
When I run Project - Clean, my config file globals.conf is gone
How can I keep my config file when I run Clean?
globals.conf should be putted under source folder, not source output folder.
Eclipse will copy all resource files(not *.java) in source folder into output folder.