I am creating a sub-folder named xml under the res folder in one of my projects. In the xml sub-folder I am creating an xml file, but this file does not show when I double-click the xml sub-folder under project explorer.
It is a kind of common bugs in Eclipse.
Try these things in order:
1. right click subfolder Xml> Refresh.
2. right click Res > Refresh.
3. File > Refresh.
& if these dont work
4. Restart eciplse
Related
I have a Java Project in NetBeans 7.0.
I want to add some image to some label dynamically. The image will differ depending on the state of the program.
I put one such image, 'filling.jpg', in the 'resources' folder of my project.
I want to reach this file correctly (not by absolute or relative path, because that will cause problems when I build the jar file).
So I found this method:
ImageIcon fillingIcon = new ImageIcon(getClass().getClassLoader().getResource("filling.jpg"));
labelFontFilling.setIcon(fillingIcon);
It keeps give me java.lang.NullPointerException.
But I am sure that there is that image, because I can assign the image to the label from the NetBeans Properties menu for that label (but I don't want this, I want to add the image by Java code).
What am I doing wrong, and how can I get that image correctly?
This was a pain, using netBeans IDE 7.2.
You need to remember that Netbeans cleans up the Build folder whenever you rebuild, so
Add a resource folder to the src folder:
(project)
src
project package folder (contains .java files)
resources (whatever name you want)
images (optional subfolders)
After the clean/build this structure is propogated into the Build folder:
(project)
build
classes
project package folder (contains generated .class files)
resources (your resources)
images (your optional subfolders)
To access the resources:
dlabel = new JLabel(new ImageIcon(getClass().getClassLoader().getResource("resources/images/logo.png")));
and:
if (common.readFile(getClass().getResourceAsStream("/resources/allwise.ini"), buf).equals("OK")) {
worked for me. Note that in one case there is a leading "/" and in the other there isn't.
So the root of the path to the resources is the "classes" folder within the build folder.
Double click on the executable jar file in the dist folder. The path to the resources still works.
I have a slightly different approach that might be useful/more beneficial to some.
Under your main project folder, create a resource folder. Your folder structure should look something like this.
Project Folder
build
dist
lib
nbproject
resources
src
Go to the properties of your project. You can do this by right clicking on your project in the Projects tab window and selecting Properties in the drop down menu.
Under categories on the left side, select Sources.
In Source Package Folders on the right side, add your resource folder using the Add Folder button. Once you click OK, you should see a Resources folder under your project.
You should now be able to pull resources using this line or similar approach:
MyClass.class.getResource("/main.jpg");
If you were to create a package called Images under the resources folder, you can retrieve the resource like this:
MyClass.class.getResource("/Images/main.jpg");
Thanks, Valter Henrique, with your tip i managed to realise, that i simply entered incorrect path to this image.
In one of my tries i use
String pathToImageSortBy = "resources/testDataIcons/filling.png";
ImageIcon SortByIcon = new ImageIcon(getClass().getClassLoader().getResource(pathToImageSortBy));
But correct way was use name of my project in path to resource
String pathToImageSortBy = "nameOfProject/resources/testDataIcons/filling.png";
ImageIcon SortByIcon = new ImageIcon(getClass().getClassLoader().getResource(pathToImageSortBy));
For me it worked like I had images in icons folder under src and I wrote below code.
new ImageIcon(getClass().getResource("/icons/rsz_measurment_01.png"));
I am new to struts. So in eclipse I don't have web-inf->classes, where I should put my struts.xml.In other project I have done this by
project->properties->java build path->output folder->browse(webcontent->web-inf->classes)->create folder(classes)->advanced->apply.
But now it is not working .the struts.xml file is now created in java resources->libraries->web app libraries.
Please see the image:
While deploying struts project struts.xml need to bee kept in web inf folder not in classes folder that is in web app folder .Once you copied your struts.xml file in web inf folder refresh your project by right click on project.
Else you can create a new dynamic web project and copy all your files[![enter image description here][2]][2]
Eclipse offers the Navigator view which will display your project in the way you are asking. To open this view select Window > Show View > Navigator. then you can see where is your struts.xml if path is not correct check it.
I am using IntelliJ IDEA 14 and I want to add file outside of src to the JAR file. This is my current project structure.
I want to add layout.txt and saveddata.txt to the JAR file executable. I've been googling on that for a while can't find the solution
In case you need to see my code. This is how I am reading file
private Path layoutPath = Paths.get("resources/layout.txt");
content = new String(Files.readAllBytes(layoutPath));
Here is my project structure
Create a folder called "resources" at the same level as "src"
Right click the folder, select "Mark Directory As -> Resources Root"
Make new directory with name as "resources" under your project root directory.
Right click on that directory and select "Mark Directory As" ==>"Resources Root" option.
It's still for me. I tried:
+ "Mark Directory As" ==>"Resources Root"
+ getClassLoader().getResourceAsStream()
+ getClass().getClassLoader().getResource()
and Thread.currentThread().getContextClassLoader().getResourceAsStream()
For me, the resources directory was already marked as Resources Root but the content was missing in the jar. I had to manually add the resources dir to the jar artifact using the Project Structure window.
Open Project Structures window
Select Artifacts and click on the + button and then select Directory Content
Choose resources directory
Press Apply then OK
In my project on eclipse I created another source folder to hold an mp3 file. Does anyone know how to access that file. What would the file path be? The reason why I did this is so this file would be included with my project when I turn it into a jar file and run it on different computers. If anyone has a better idea on how to do this feel free to contribute!
right click on your project > properties > resources > location
if you want to programmatically go there generally eclipse starts jvm with working directory set to base of project so you can navigate from new File(".")
Check the getResourceAsStream method from class Class: http://www.tutorialspoint.com/java/lang/class_getresourceasstream.htm
In spring:
ResourceLoader resourceLoader;
final Resource resource =
resourceLoader.getResource("classpath:com/XX/XX/" + filename);
in Eclipse, right-click on your project and select "Properties".
With "Resource" selected, it shows "Location:" which is the path to your project.
Let's say if you added a folder to your project called Audio, then you could access a mp file like this:
new File(".\\Audio\\MyAudioFile.mp3")...
I need to change the name of my application, so people who download and install it can see the name but I don't know where to do it.
What file do I need to edit?
you must right click on your project in Project window [ctrl + 1] and choose rename option for
renaming your project name.
if your project is mobile Project you must right click on project name , select properties options and then on Application Descriptor edit MIDlet-name value.
If you use gradle:
BuildScripts/Project/settings.gradle
rootProject.name = 'yourprojectname'
If your project is Maven based, you can either add/update the application name in pom.xml (found in Project Files folder) or go to File >> Project Properties and add/update the application name.
Open "project.xml" file under nbproject folder inside the project folder of the one you want to change the name.
it is in the tag <name>.
Just change it and that is it.
open project.properties in dir nbproject
look up to manifest.midlets and change the name after MIDlet
Rightclick on the project node and select rename.
If you want the folder of the project also to have the new name or whatever that wasnt renamd then :
1.in build.xml in text editor find old name and replace with new one. Its place is: C:\NBProjectsFolder\OldName\build.xml Save that.
2. Remove all cash situated in , e.g.: C:\NBProjectsFolder\OldName\build\gwt-unitCache.
3. Find in C:\NBProjectsFolder\OldName\nbproject\private private.xml file and edit it in a text redactor by renaming old name within the file. Save that.
Do all the changes when the Netbeans was closed.
After opening the Ntbeans it may ask to reimport the project and all files you changed will be recognized/recreated automatically