Question

My project is written on ZK and uses as several XML files as resource files. These files are parsed manually when pages are being loaded and represent the logics of the application. On local machine I used to store these files in eclipse root directory, as server (Tomcat 6.0) used to search for them there. What is the right way to upload these files to Jelastic cloud?

Was it helpful?

Solution

Your web application can (and should, usually) be packaged as a self contained file so you don't need to worry about where dependencies like these might be on different deployment locations. This question, then, is not about ZK or Jelastic as much as it's about how to package resources within a war.

The standard Java approach is to have the resource files end up in the classes folder of war. You can then access them with..

foo.bar.Baz.class.getResource("xyz.txt");
foo.bar.Baz.class.getClassLoader().getResource("foo/bar/xyz.txt");

Credit to @JonSkeet

To get the files there, you can put them right in your Java package structure (usually not the cleanest approach) or use your build process to put everything together for you. Using Maven you just need to put your XML files in src/main/resources/. Using Ant you can include these files from where ever.

Another approach is to put your resource files in the WEB-INF/ directory. There they can be accessed using with..

servletContext.getResourceAsStream("/WEB-INF/myfile");

Credit to @skaffman

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top