• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Tomcat7 deploying app with custom files

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In NetBeans,
To use a folder called "ErrorSet" i use this line:

File file = new File("ErrorSet/error_list.xml");
It is necessary to import this file because it contains custom error codes, to the point:

When you want to import something in a netbeans project, the default "root" from where you use the files is the project name folder like [projectName]/ErrorSet/error_list.xml ...

Where do i need to place the ErrorSet folder when deploying the [projectName].war from dist folder in tocmat7 so that i can use new File properly? What does the File("ErrorSet/error_list.xml") parent directory become since its in tomcat7?
 
Saloon Keeper
Posts: 28663
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Robert!

Um.

If your IDE is an integral part of your webapp, you're too dependent on the IDE. It won't be there when the app goes into production.

Tomcat is a J2EE-compliant web application server. That means that all Tomcat applications are in the form of a WAR. The format of a WAR file is a well-defined part of the J2EE/JEE specification, but it's essentially a JAR, which in turn is a ZIP file, with a few pre-defined components.

When a WAR is unzipped ("exploded"), it makes a directory tree, and every part of the webapp is located within that tree. That means that when you deploy a webapp, there's only one file (the WAR) that you import into the webapp server.
 
Robert Artenie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Welcome to the JavaRanch, Robert!

Um.

If your IDE is an integral part of your webapp, you're too dependent on the IDE. It won't be there when the app goes into production.

Tomcat is a J2EE-compliant web application server. That means that all Tomcat applications are in the form of a WAR. The format of a WAR file is a well-defined part of the J2EE/JEE specification, but it's essentially a JAR, which in turn is a ZIP file, with a few pre-defined components.

When a WAR is unzipped ("exploded"), it makes a directory tree, and every part of the webapp is located within that tree. That means that when you deploy a webapp, there's only one file (the WAR) that you import into the webapp server.



Got that, i know that libraries go in Web-Inf/lib folder for example, so where should i put my custom folder...? What if you have to create folders in that app, for example when user uploads a foto and you want to store it in the username folder, where will that folder create?
 
Tim Holloway
Saloon Keeper
Posts: 28663
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's important to distinguish between a webapp URL and a webapp resource.

A URL is how an external client accessed webapp functionality.

Webapp resources are the files that are used as inputs to resolve URL requests. People confuse them with URLs, because the syntax of a URL path (https://coderanch.com/user/list") and the syntax of a resource path ("/user/list") look a lot alike. But they are very different things.

When a URL request comes into a webapp, the server checks the URL pattern lists defined in the /WEB-INF/web.xml resource for a match. It it finds one, it matches it to the corresponding servlet and sends the request to that servlet. If no URL match is made, the URL is translated to a resource pathname (the protocol, servername and context parts are removed from the URL, as is the query string and/or anchor path). The WAR is then examined for a resource at this path, first as a JSP, then as a plain resource (such as a stylesheet, image, or javascript). If it's a plain resource, the contents of that resource are copied out to the Http Response stream.

So, if you want to return "ErrorSet/error_list.xml", to a client, you'd code a URL something like this: http://myserver.com:8080/mywebapp/ErrorSet/error_list.xml".

On the other hand, if you have a servlet that wants to read and use the error_list.xml file internally, you'd access it via a getResource() or getResourceAsStream("/ErrorSet/error_list.xml") method call. The getResourceAsStream method is especially useful, since it returns an InputStream all ready for reading. The location of that resource relative to the WAR root is therefore "/ErrorSet/error_list.xml".

Note that I18N message bundles and similar constructs based on the java system Properties class actually expect to find their values in property files located in the WAR classpath. That is, under /WEB-INF/classes.

As to how these various resources get moved from whatever editing locations they are in to the actual WAR, that's the IDE's decision, as is the location of the editing location itself. The IDE forum is a better place to ask that question.
 
reply
    Bookmark Topic Watch Topic
  • New Topic