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
Related
I have a multi-module Spring Boot Gradle project (Kotlin) with the following directory structure.
root
|- domain (Module containing entities and interfaces)
|- application (Spring boot Kotlin application)
|- src/main
|- kotlin (app sources)
|- resources
|- application.properties (default config)
|- src/test/kotlin/long/package/name/ApplicationTests.kt
|- build.gradle.kts (and also gradle folder)
|- config
|- application.properties (config to override classpath properties)
|- build.gradle.kts (and settings.gradle.kts and other gradle folder)
When I run the Application.kt file, it is able to pick up this file (both with IDE and gradle), and it runs successfully.
Since my config folder is outside my application folder, running my ApplicationTests.kt results in the error below. The output is same when running through IDE (IntelliJ) run button and ./gradlew clean test.
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
I am expecting the tests to find the application.properties file inside the config folder. How can I register my config/application.properties so that I can keep it separate from my classpath:application.properties?
UPDATE:
I tried adding the following copy task to gradle.
tasks.create("copy", Copy::class.java) {
from("../config")
into("$buildDir/resources/main")
}
tasks.named("test").configure {
dependsOn("copy")
}
This enables me to overwrite the application.properties from config folder (meaning any property not added in config/app.prop is no longer present). Test runs successfully now (if I add all entries from classpath properties to config/app.props). How can I merge the contents of these two properties files inside application/build.gradle.kts?
If you want to override your application.properties with an external application.properties, you can copy the external file to build/classes directory using Gradle and append a profile name, like application-ext.properties. Then, activate default and ext profiles using spring.profiles.active.
Another option would be to use Spring Config server, but that may be overkill for this simple task.
By default, Spring will look in your current working directory for the directory named, config. As you've noted, you're not executing the application in the directory containing the config directory. You can override where Spring looks for this config folder with the -Dspring.config.location option or via the environment variable, SPRING_CONFIG_LOCATION
If your config directory is located at /opt/myconfigs/config, you would start your service with -Dspring.config.location=/opt/myconfigs/config. Another option is to export SPRING_CONFIG_LOCATION=/opt/myconfigs/config and start your app without any additional JVM options.
If you're running tests in the application directory, then the config folder would be one level up from the current working directory. Annotating your tests with
#TestPropertySource(properties = "spring.config.location=../config/,classpath:/application.properties") would load the application.properties from both the config folder and the src/main/resources folder, properties in the config props would override properties in the local application properties.
The same thing can be achieved with the VM argument of -Dspring.config.location=classpath:/application.yml,file:../config/, here order is important.
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?
I'm following a YouTube tutorial on twilio sms service, and I came to a point where I have to create my own .rb file! My project directory at the moment looks something like this:
The tutorial uses atom my_ruby_file.rb in the terminal to create a new ruby file. However, I do not use atom and from what I understand rails have changed a lot since 2014 that the video was recorded!
So my question is: Where to create my custom ruby files for Rails 6.1.3.2? I have noticed in my directory that .rb files are used all over the place. For example controllers and models and more, but where do I have to set one created by me ?
Related Question:
Where to keep other custom files such as .js, .css, .png ? The way I did it is to create a new folder in the following directory project-name/app/javascript/my_custom_files/js/dial_codes.js and actually reference that in the project-name/app/javascript/packs/application.js using this command require("my_custom_files/js/dial_codes"). Is this the correct way of doing that for that specific rails version?
project-name
|
|- app
|- assets
|- channels (application_cable)
|- controllers (concerns) -> contains application_controller.rb, friends_controller.rb, home_controller.rb
|- helpers
|- javascript (channels, packs, my_custom_files) -> For custom JS, CSS, images using webpacker
|- jobs
|- mailers
|- models (concerns) -> contains application_record.rb, friend.rb, users.rb
|- views (divise, friends, home, layouts)
|- bin
|- config
|- environments
|- initializers
|- locales
|- webpack
|- db
|- lib
|- log
|- .node_modules
|- public
|- storage
|- test
|- tmp
|- vendor
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.
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