I've just changed to eclipse an I'm used to manually managing my project structure with Windows filesystem (compiling my .java files into bin with a batch-script). Whenever I wanted my classes to use a .png-file, I simply put this file into the .bin folder.
If I put my .png-files in the bin-folder of the eclipse project as I'm used to, the classes will be able to load the pictures just fine. But sometimes, I don't know when, Eclipse simply deletes the bin-folder and creates a new one based on the contents of the src folder (which doesn't have my .png files). Putting the files into the src-folder (again, manually from the windows file-system) doesn't actually put them in my Eclipse project.
So what I want to ask is: Why/when does Eclipse completely rebuild the bin-folder. And how can I put resources, like .png-files, into my Eclipse project?
of course there is no point in putting files in the bin as it may be rebuilt by Eclipse whenever needed and you'll loose your changes.
by default Eclipse is set up to rebuild the project automatically, you can see that by looking in the "Project" menu entry, you can force Eclipse to rebuild your project by choosing "clean" in that "Project" menu.
So now you should have more control over when Eclipse is building your project.
Regarding adding resources files, I'm not sure what your current project directory structure is, in order to add / remove directories in the project, right click on the project root in the project Explorer side pane and choose "Properties" entry (at the bottom), then you can go to "Java Build Path" -> "Source" tab and manage the project directories.
last, if you change files on your disk and not through Eclipse, right click on the project root and choose "refresh" entry.
Hope this helps.
Related
I'm having difficulties creating a Java project in Eclipse on the same location where the deleted project was. What happens when I change the new project location to the one where the old project was is all my options become grayed out. I cannot select the JRE or change the project layout. I cannot pick whether I want to create module-info.java file or not. It seems like Eclipse somehow knows there was a project on the same location. If that is the case, how can I delete Eclipse Project creation history?
New Java Project dialog info message:
The wizard will automatically configure the JRE and the project layout based on the existing source.
When you delete a project in Eclipse, you get a dialog like this:
As you can see, the default is that the project content is not delete, only the project registration in Eclipse.
Since the actual project files are left on disk, you can "import" the project back into Eclipse, using File > Import....
When you try to create a new project, but select a folder on disk that already contains a project, the "Create Project" dialog automatically becomes an "Import Project" dialog.
If you don't want to import that project, either select another folder, or delete the folder first.
Next time you delete a project, check the Delete checkbox, so all the project files and source files are deleted too.
Make sure you have deleted all the hidden files in the directory.
Make sure it's deleted on your machine in your file explorer. If it's not deleted correctly it can still be save on your machine.
I have done a reasonable amount of programming in various languages but I am a Java / Netbeans newbie. I have successfully created and run "Hello World" so my Netbeans installation is OK.
I want to write code to control an LED display controller card. I have sample demo code zipped up by the OEM. I am trying to import, run and edit that code. If I can get this running, this will be the starting point of my own code.
The zip files only include library and source files in a directory structure that does not match Netbeans. All of my attempts to import the source and lib files have given fatal errors in Netbeans.
The directory tree has a lib and src branch at the root. The src branch cascades 4 levels to get to the source files.
I figure if I use a different tree structure, I will need to change the import statements in the source file. I'd rather not touch the code until I have it running. I have tried to unzip the project tree directly into the Netbeans directory but that didn't work.
How to import a JAR (Java Archive, the "library" in your case) in Netbeans:
Right click on your project name, in the 'Projects' pane usually located on the left
Click the 'Properties' link from the pop-up menu
Click the 'Libraries' link in the Categories list
Choose 'Add JAR/Folder', browse to your JAR and click OK
If you want Netbeans to create the JAR for the sources you have, do like Stefano says.
You should package the src folder as src.zip with a zip utility and the structure under lib with the java archiver as a jar file.
Now you can define a library in NetBeans and add these files to it (Tools => Libraries => New Library).
For Netbeans to be able to open a project, the folder has to contain some files that Netbeans itself generates when a project is created.
Since you only have src and lib folders available, I think the easiest solution would be to create a new project from Netbeans, so that the creation of those files is automatically managed, and then copying the content of the folders you have in the folders Netbeans will create.
You will also have to tell Netbeans to use those library, and you can do that from you new project's preferences.
Edit
A few more things you can try:
in NB, right click the folder containing the JARs you imported and select "remove", then import them back but selecting the jar files instead of the whole folder;
if you're not already doing so, use the "Clean and build project" button instead of "Build project";
If none of the above solve the issue, try starting from scratch again following these steps:
unzip your OEM files somewhere in your disk;
create a new empty project in NB
copy the files from the src OEM subfolder to src NB project subfolder
in NB, right click Libraries, then add JAR/Folder and select the jar files from the lib OEM subfolder
If this doesn't work either, tell me where I can find the OEM stuff and I'll try it myself :)
I have a problem with my war.xml file in that it isn't picking up my class files correctly for spring.
The line that is wrong is:
<dir sourceOnDisk="C:\myApp\src\main\java" targetInArchive="/WEB-INF/classes"/>
I need:
<dir sourceOnDisk="C:\myApp\bin" targetInArchive="/WEB-INF/classes"/>
Now, I can change the file manually (from src\main\java to bin), and it works correctly for a while, but every now and again something decides my war.xml file needs to be rebuilt, and things then break again.
I added my application by dragging my project from eclipse's Project Explorer tab to my liberty profile server instance within eclipse's Servers tab.
Where is the menu option within eclipse to change this?
To automatically map your bin folder to the WEB-INF/classes folder, select your project on the Project Explorer, right click it and select Java Build Path. In this property page on the Source tab, you can add, edit or remove the source folder, and also modify the default output folder. In this case you may only need to modify the output folder, to something similar to (project-name)/bin
Regarding the *war.xml file located at (server-dir)/apps, this will be refreshed each time you modify your project in eclipse, if when doing it, you have your server started and with automatic publish enabled. Usually you don't modify this file yourself, but you can read more about it here: http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.wlp.nd.doc/ae/rwlp_loose_applications.html?cp=SSAW57_8.5.5%2F1-14-1-10
Turns out the correct place to change things is in the Deployment Assembly option when you right click on your project...
I was rearranging some files in eclipse, and I accidentally deleted the default output folder. This is the location where eclipse stores the class files. Can anyone show how to recover it? Or rebuild it from the .java files?
EDIT:
I just restored the project from backup files. So this question is no longer relevant. Unless some future reader did not backup their application before making this same mistake.
from the menu bar select:
Project->Clean...
That will bring up a dialog box to select which projects to rebuild. The bin directory should be automatically regenerated.
Recompile your project, and Eclipse should create it again (default name is bin on some versions)
If not, navigate to your project settings, and go to
Java Build Path > Sourceand at the bottom you will see the default output folder. You can create it again by using the Browse button, and then Create new folder
All you need to do is re-compile your project, For that you can select your Project and do Ctrl+B or just select Project->Build Project
EDIT:
As you mention in the comments that you still do not see the class files. Please check the Default output folder by selecting your project Right-click Build Path -> Configure build path... then select Source tab and see what the Default output folder: mentioned there, your class files must be created there.
This problem has been frustrating me for some time...
A lot of sites like Sourceforge use SVN or Subversion to manage their code. I have little problem compiling SVN code in C++, but when it comes to Java, my IDE gives me a headache.
I've installed Subclipse for SVN support for Eclipse, and it works. I can check out any code into my Workspace. Now Subclipse will put the whole thing into a special project of some sort that can't be compiled. So I search Google for something and I come up with modifying the eclipse XML file to specify the 'nature' to be a Java project.
Okay, now it's a Java project. Say I have a folder structure like:
\src
\data
\graphics
I get 800 compiler errors complaining the package name is org.company.SomePackage instead of src.org.company.SomePackage.
Then what I do is create packages called src, data, graphics, etc, instead of just folders. I cut and paste everything in the folders into the packages and finally I can compile it.
What is a better way to do this?
EDIT: I can only check out anything SVN as a SVN project, and there's no way within Eclipse to change that to a Java project. How can I check out the SVN as a java project in the first place?
I get 800 compiler errors complaining
the package name is
org.company.SomePackage instead of
src.org.company.SomePackage.
Right click on Project -> Properties -> Java Build Path -> Source Tab -> Add "src" as a source folder and remove any others.
it thinks your source is stored in root folder. you need to specify to the project that /src is the source folder.
In general when we have an Eclipse project, which contains Java code – but we didn’t set it up as a Java project when we created or checked out this project, we are struck. And Eclipse doesn’t allow to change the project type inside the Gui. So we need to add the java nature as below.
1. Close your project.
2. Open your project file (which is located in your root directory of the appropriate project) called .project with your default editor. Search for
< natures>
< /natures>
and change it to as below
< natures>
<nature>org.eclipse.jdt.core.javanature</nature>
< /natures>
Save the changed file.
3. Open the project again – now it should become a java project.
Then do the following as explained by Kevin
On the Project Explorer Window ->Right click on the specific Project -> Properties -> Java Build Path -> Source Tab -> Add "src" as a source folder and remove any others.
For me when I went into “Source Tab” – the “src” folder was already added, but it was not giving me the desired result (ie I was still not seeing the .java files in the project explorer window). So I removed the “src” filed that was already added in the Source Tab and then added them again. And then all worked fine.
You have to configure proper source paths. Some open source projects make this automatic by checking their .project and .classpath files in with the rest of their files. For others, you'll have exactly the problem you are having. You need to set the classpath so the Java compiler knows where to find the source. You right click on the project and select properties and configure an arbitrary classpath, but the answer given by Kevin is easier for a beginner.