I'm working on a project which uses JAAS and unfortunately for me Tomcat requires a file to be put in a META-INF folder in the root of the war
app.war
|__META-INF
| |___context.xml
...
I think that it's already weird since the default META-INF location for WAR's is in the classes folders.
app.war
|__WEB-INF
| |__classes
| |__META-INF
...
So I'm using Maven, which states that anything in src/main/resources/META-INF will be copied to the appropriate place, which it does. The weird thing is that it is also creating a META-INF folder in the root of the file structure leaving me with 2 META-INF folders.
Project Structure
app
|__src/main/java
|__src/main/resources
| |__META-INF
| |__context.xml
...
After mvn package
app
|__META-INF [1]
|__WEB-INF
| |__classes
| |__META-INF [2]
| |__context.xml
...
So, if the war standard states that META-INF should be under classes folder, as in #2, why maven war creates the #1 folder. And is there a way to make it copy files into that folder instead of #2?
Regards
So I found this:
Two Meta-Inf folders - normal structure?
which states that having 2 META-INF folders is not a problem. Digging a little I found:
JAR File Specification
which states about the META-INF folder:
A JAR file is essentially a zip file that contains an optional META-INF directory. ...The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services.
and this:
JSR-000315 JavaTM Servlet 3.0
which, on section 10.6, states about the WAR file structure:
When packaged into such a form, a META-INF directory will be present which
contains information useful to Java archive tools. This directory must not be directly
served as content by the container in response to a Web client’s request, though its
contents are visible to servlet code via the getResource and getResourceAsStream
calls on the ServletContext. Also, any requests to access the resources in META-INF
directory must be returned with a SC_NOT_FOUND(404) response.
So from the WAR spec the right place is WEB-INF/classes/META-INF. Yet, since war is a special jar file, it makes sense to have /META-INF as a point for extensions. One can see such different uses in JPA persistence.xml vs. Tomcat context.xml files: the former should be placed in WEB-INF/classes/META-INF while the latter in /META-INF.
Related
my-project
|
|-kube
|_kustomize
|_base
|_sql
|_dbsturct
|_liqubase
|-db.changelog-master.xml
|-src
|_my.java.code
|_ resources
In my project I kept database-chagelog.xml outside resources folder and not included in the classpath.This folder structure is not included in the pom.xml as part of resources.
I have configured spring.liquibase.change-log=file:///C:/my-project/kube/kustomize/base/sql/dbsruct/liquibase/db.changelog-master.xml
It throws file not found exception.
Is there a way to configure db.changelog-master.xml without including as resource folder inside pom.xml?
In SPRING MVC project, Which is the right folder location to create a new JSP(view) file:
WebContent\new_jsp_file.jsp
or
Java Resources\src\com.example.view\new_jsp_file.jsp
Note: com.example.view is a manually created package
Usually JSP file is located here:
%projectfolder%/src/main/webapp/WEB-INF/jsp/
JSP files should be put inside WEB-INF directory, because contents of WEB-INF aren't directly accessible by users, which is needed for application security.
If you are using Maven or Gradle:
project-name
|- src
|- main
|- java
|- resources
|- webapp
|- WEB-INF
|--- put JSPs here, can create subdirectories if needed
How can I override server.xml or context.xml file of tomcat 8 from project? Because I am using data source in server.xml.
You cannot override the server.xml from your project. On the other hand you can override context.xml. You can do so by (c/p from docs)
In an individual file at /META-INF/context.xml inside the application
files. Optionally (based on the Host's copyXML attribute) this may be
copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to
application's base file name plus a ".xml" extension.
As described, to override context.xml you should add a META-INF to your webapp's root and place inside your context.xml. Note that in order for your projects context.xml to take effect, there should not be already set context.xml for that particular project inside tomcat instance
In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context
path and version will be derived from the base name of the file (the
file name less the .xml extension). This file will always take
precedence over any context.xml file packaged in the web application's
META-INF directory.
I want to create /java, /resources, and /webapp/WEB-INF/web.xml folder structure under src.
I have used the -DarchetypeArtifactId=maven-archetype-webapp but it creates /resources /webapp/WEB-INF/web.xml but doesn't create /java folder.
So in spite of creating the folder /java in eclipse manually is there any other way to create with some -DarchetypeArtifactId= so that it creates the above folder structure.
I'll be thankful if someone can tell me how can I customize and design my folder structure and create it with maven without using existing template.
When you use -DarchetypeArtifactId=maven-archetype-webapp, java folder wont be created. It needs to be created manually.
It created the following structure
src
└── main
└── resources
└── webapp
└── WEB-INF
Best choice is to follow Maven standard directory layout:
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
Archetypes are minimized due different programming languages can be used for web development:
http://cvs.peopleware.be/training/maven/maven2/standardDirLayout.html (link goes to web.archive since the main link is dead)
It will minimize configuration of plugins and also will simplify understanding and maintenance of Maven projects
you can create a Maven Webapp using following archetype
-DarchetypeArtifactId=maven-archetype-webapp
which will automatically creates the desired folder structure
in your case its apart from src\main\java
src\main\resources
src\main\webapp
How can I add META-INF/context.xml into the war? I didn't find any config entry in config/warble.rb.
Unfortunately Nick's method doesn't work. The file is actually copied to WEB-INF/META-INF/context.xml.
I finally figure out a way to copy context.xml to META-INF:
create META-INF/context.xml under your rails app root folder
uncomment and change the following line in config/warble.rb
config.public_html = FileList["public/**/*", "doc/**/*", "META-INF/context.xml" ]
Basically treat META-INF as public_html, and it will be copied to webapps/youapp/META-INF.
You'll have to add one yourself. You can either create a META-INF/context.xml directory and file in your project and add META-INF to config.dirs in config/warble.rb or you can add a "pathmap" to rename the context.xml file into the META-INF directory in the war file.
config.pathmaps.application += ["%{context.xml,META-INF/context.xml}p"]
A better way of tackling this might be to use the following in your warble.rb file.
config.script_files << 'path_to_file/context.xml'
See documentation towards bottom of https://github.com/jruby/warbler/blob/master/lib/warbler/config.rb
# These file will be placed in the META-INF directory of the jar or war that warbler
# produces. They are primarily used as launchers by the runnable feature.
attr_accessor :script_files