1

I have an eclipse JSF example where the ExampleController class cannot find the Bundle.properties file. Here is the dynamic web project snapshot that was used to create the JSF project,

Dynamic Web Project

Here is a snapshot of the project file structure. You can see the bundles file in properties folder,

Project file structure

Here is a snapshot of the class code. Notice the file name in the getBundle methode,

@ManagedBean(name = "exampleController")
@RequestScoped
public class ExampleController {
    private String exampleProperty;

    * Creates a new instance of ExampleController
    */
    public ExampleController() {
        exampleProperty = "Used to instantiate the bean.";
        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, 
                        ResourceBundle.getBundle("WebContent/properties/Bundle.properties").getString("ExampleMessage"), null);
    FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}

Finally, here is a snapshot of the error when I run the code against the tomcat server,

Runtime Tomcat Server Error

I have tried several combinations of file names but continue to get file not found errors when the server runs. What am I missing?

Best Regards, Steve Mansfield

skmansfield
  • 1,413
  • 3
  • 19
  • 41

1 Answers1

0

Try to play with the path. The "WebContent" in your path does not seem right. Usually the resource path gets resolved relatively to WEB-INF or current class-file location. You could also try to put your properties directory in several places, to see if it gets picked up in one of those. :)

Also if you could get your hands on where the built project is actually run from "physically" (if it is not from these very files) maybe you would find out the properties file does not get copied with your other files. (Do you have Deployment Assembly in your Project settings? If so, check it out.)

UPDATE: If you simply need to open a properties file, check this one out: getResourceAsStream() is always returning null ...I don't know if your folder is special in some way tho.

Most often when Tomcat starts acting weirdly in Eclipse I find out that Deployment Assembly is f****d up. (Happens with Mavenized projects. Eclipse and m2eclipse aren't the best friends it seems.)
Such situation fits the scenario "works when deployed to production server, does not when run from within Eclipse."

Community
  • 1
  • 1
Jaroslav Záruba
  • 4,694
  • 5
  • 39
  • 58
  • I agree with you comment "maybe not in WebContent". I took it out and ran again with no luck. I took the file out of the folder and placed in several places in the project but still no luck. Anyway I can see where Tomcat is actually looking for it? – skmansfield Mar 11 '15 at 22:12
  • It could be at workspace/.metadata/.plugins\org.eclipse.wst.server.core/tmp0 or tmp1 etc. (that is if you are running Tomcat from within Eclipse) – Jaroslav Záruba Mar 11 '15 at 22:16
  • Yes, I am running eclipse with Tomcat. – skmansfield Mar 11 '15 at 22:28
  • It seems so simple but yet I have been trying multiple file locations and file pointers. Yes, I am running Eclipse Lunar with Tomcat 7.0. Actually the project was built using the eclipse Amazon Web Services plugin. I initially run it locally on the Eclipse Tomcat server to make sure it works correctly. Once debugged I deploy to a AWS Beanstalk instance for final verification. Anyway, I have had several other projects work successfully on both the local Tomcat server and the AWS Beanstalk Tomcat server. However, I have not been able to get any to projects to work with a local file. – skmansfield Mar 11 '15 at 22:43
  • I have had other projects that had css and html files work with no problems. I put both in folders in the META-INF folder and everything worked fine. However, anytime I reference a file from Java I can't seem to find the correct filepath. – skmansfield Mar 11 '15 at 22:47
  • They are treated in a different way, I mean comparing static resources and Java source files helps you in no way, they are treated very differently. – Jaroslav Záruba Mar 12 '15 at 00:02
  • 1
    The issue, although not really an issue, was that the compiler/RecourseBundle.getBundle() treated the file as java source code and used the Java Build Path "source" reference. My java source build path was set to "Recipe03_06/src. Once I placed the file in src everything worked. Their was one other thing. ResourceBundle.getBundle() did not like a file extension. I had to remove the file type. So placing the file in "Recipe03_06/src" and removing the file type reference in getBundle() enabled everything to work. Big shout out to Jaroslav for giving me the hint on class path. – skmansfield Mar 12 '15 at 13:10