Property file not available in bin folder while building in Eclipse - 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.

Related

Path to .class file in eclipse

I know eclipse automatically build java files.When compiling we will get Class files normally.When we run java file from eclipse where we can see generated .class files?
1. For this you have to go to Window->Show view->Navigator
2. Now there will be a window opened on left side where you can explore all folders including "build" folder.
3. Here in build folder go to ->classes->This is the place where you can Find all your .class Files
Hope This will answer your Quest .
Right click on your project name in Project Explorer and click Properties from menu
Go to Java Build Path from left menu on the popup
Click on Source tab on the page
See the Default Output Folder option which is what you are looking for
in the bin folder of your eclipse project
When you go to the project build properties > build path option.
Open build path settings for your project by right clicking
Go to source option
There you can see source directories as well as default output folder. That is where the class files will be generated.
Either you can set it during project creation like this: here output folder is ptll
Or you can see the default output folder for java in preferences > java
In my case i have both src and target folders in maven project path once project build is done, Go to Windows -> ShowView -> Navigator -> (Project Path) -> target(folder) -> classes(where you can find all the classes that compiled from the src folder)

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

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.

How to create a Jar file in Netbeans

Well I have my source code that i have done using the IDE netbeans. Now I wanted to move this java application to a web application. For that I need to create a jar file from my source code, so that I could invoke it in ma jsp file.
I have not been able to find any option in netbeans or any other way to create a .jar file of this source code.
Could someone tell me how to do that.
Thanks
Create a Java archive (.jar) file using NetBeans as follows:
Right-click on the Project name
Select Properties
Click Packaging
Check Build JAR after Compiling
Check Compress JAR File
Click OK to accept changes
Right-click on a Project name
Select Build or Clean and Build
Clean and Build will first delete build artifacts (such as .class files), whereas Build will retain any existing .class files, creating new versions necessary. To elucidate, imagine a project with two classes, A and B.
When built the first time, the IDE creates A.class and B.class. Now you delete B.java but don't clear out B.class. Executing Build should leave B.class in the build directory, and bundle it into the JAR. Selecting Clean and Build will delete B.class. Since B.java was deleted, no longer will B.class be bundled.
The JAR file is built. To view it inside NetBeans:
Click the Files tab
Expand Project name >> dist
Ensure files aren't being excluded when building the JAR file.
Please do right click on the project and go to properties.
Then go to Build and Packaging.
You can see the JAR file location that is produced by defualt setting of netbean in the dist directory.
I also tried to make an executable jar file that I could run with the following command:
java -jar <jarfile>
After some searching I found the following link:
Packaging and Deploying Desktop Java Applications
I set the project's main class:
Right-click the project's node and choose Properties
Select the Run panel and enter the main class in the Main Class field
Click OK to close the Project Properties dialog box
Clean and build project
Then in the fodler dist the newly created jar should be executable with the command I mentioned above.
Now (2020) NetBeans 11 does it automatically with the "Build" command (right click on the project's name and choose "Build")

How do I change a Java project's bin folder in Eclipse?

When you have a Java project in Eclipse, how do you change the location where the class files are placed? The bin directory is the default location.
You can change the folder name from bin to something else.
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.
But you cannot change the directory. For example if your project is in D: drive you cannot keep the output folder in C: drive.
Right click on your project and select Properties.
Java Build Path --> select the Source tab
See the below image for more details:
Right-click on our project --> select properties --> select Java Build Path --> select the Source tab. At the bottom of the tab you should see a field named (Default Output Folder:).
I would like to describe an approach below.
First, create a new empty project locally in eclipse work space for storing generated output files say output_bin.
As mentioned in above steps, now from Default Output Folder we need a new Variable to link to our project output folder.
Default Output Folder -> Browse -> Create New Folder...
-> Advance -> check "Link to folder in the file system" ->
Variables -> New.. -> Name = PROJECT_OUT, Location = "CHOOSE_PATH_TO\output_bin\bin\Project1bin" -> Ok
Note: Project1bin is a new directory which stores the bin folder. output_bin is an empty project and you can have multiple bin folder for various projects.
These answers only describe changing for one specific project.
But if you are using a build tool in Eclipse such as Gradle, you are likely to get annoyed by spurious build errors caused by class files being produced under \bin... the best thing is therefore to change the default output folder:
(Eclipse Mars)
Window --> Preferences --> Java --> Build Path --> Output folder name: change from "bin" to "build"
NB be aware, however, that this (currently) only appears to work when you create a new Java project using the Java project wizard. I import Gradle (STS) projects and find that I nevertheless have to change manually from "bin" to "build" for each project.