what is the difference between these two folders? Why my beans have to go in resources, so my web app to work?
src/main/java Application/Library sources
src/main/resources Application/Library resources
The src/main/java contains your java source codes. that is, your java packages, *.java files.
The src/main/resources contains "resources" file of your project. e.g. properties file, configuration files (xml, ini, conf....) they are in classpath of your project.
Usually the compiled sources (*.class files) and those resources would be in target/classes.
Your web app sources (e.g. Jsp/jspx, js, html...) should go to src/main/webapp
Related
I am new to java and I have been learning things recently that gets me started up like packaging, naming convensions, resources folder and similar stuff the right way.
My question right now is,
I see some people using the libraries/natives folder like this
Project -> src -> libraries
and as well
Project -> src -> natives
but some other people do have them in a resource folder like so
Project -> src -> resources -> libraries
and as well
Project -> src -> resources -> natives
So I am not sure which one is more correct, but I guess it should be in resources, since they are part of them. Please explain to me.
A common convention is the Maven Standard Directory Layout, core part being:
src/main/java Application/Library sources
src/main/resources Application/Library resources
If you're using Maven, then there is no libraries folder, since Maven is responsible for managing the .jar files, otherwise .jar files and associated native .dll/.so files are usually put in a lib folder next to src. Alternatively, the native .dll/.so files are put in a bin folder, which contains all files that should be on the PATH.
src/main/java Application/Library Java sources (.java)
src/main/cpp Application/Library native sources (.cpp)
src/main/resources Application/Library resources
lib Third-Party libraries (.jar)
bin Third-Party native files (.dll, .so)
and Application/Library scripts (.bat, .sh)
I have a Maven project in Eclipse which I am using to build a Spring MVC application. However, I am very confused about how the project structure should be. I've looked at various sources online and they often differ.
My current project structure (a bit of a mess..):
Which source folders do I need in Java Resources? Obviously src/main/java and src/test/java but what about src/main/webapp? What goes in there?
I see that there is a src directory generated when I build the project. What's the purpose of this directory?
Do I put my static resources e.g. 'style.css' in WebContent/resources or in a different directory?
Finally, how should my Deployment Assembly mappings look?
Update as per suggestion (not yet solved):
src/main/webapp contains the css html and js related files. if you are aware of webContent folder the same things resides inside the webapp folder.You will need to remove the webcontent folder and place all the files in src/main/webapp folder.
So I'm learning web application development and I'm a bit confused about how to organize my files in the template provided by eclipse for Dynamic Web Application.
Should I place my HTML pages in WebContent? Where do I put the JSP and servlet source files? What convention is globally followed?
This is the structure of the template provided by eclipse
Deployment Descriptor
JavaScript Resources
WebContent
ECMAScript Built-In Library
ECMA 3 Browser Support Library
src
JRE System Library
Apache Tomcat v8
Web App Libraries
EAR libraries
build
WebContent
META-INF
WEB-INF
lib
Place HTML and JSP pages in the WebContent directory.
The Eclipse help page referenced by android-weblineindia states that WebContent is:
The mandatory location of all Web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory (or in a subdirectory structure under this directory), the files will not be available when the application is executed on a server. The Web content folder represents the contents of the WAR file that will be deployed to the server. Any files not under the Web content folder are considered development-time resources (for example, .java files, .sql files, and .mif files), and are not deployed when the project is unit tested or published.
so CSS files and JS files needed by the browser should also be placed here.
Place java source files (so including servlet sources) in the src directory. The same help page states this for the source directory (although it suggests it is called JavaSource which looks like an error in the documentation):
Contains the project's Java source code for classes, beans, and servlets. When these resources are added to a Web project, they are automatically compiled and the generated files are added to the WEB-INF/classes directory. The contents of the source directory are not packaged in WAR files unless an option is specified when a WAR file is created.
If you look at project Properties -> Deployment Assembly you should see that files compiled from src are deployed to WEB-INF/classes and files in WebContent are deployed to the root of the WAR file
I've created small program in Java. It uses Java classes, some images and generates some other resources (.php files, images, stylesheets etc).
I'm compiling sources as .jar and creating an .exe program, which should use my .jar and other resources.
What is the best practice to organize all sources of my Java program?
I will recommend the below maven structure as the standard convention even if you are not using maven.
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/scripts Application/Library scripts
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project's license
NOTICE.txt Notices and attributions required by libraries that the project depends on
README.txt Project's readme
When i create a new Maven project in Eclipse, directory structure contains both src/main/java and src/main (down below)
Question:
I understand my code should fall under src/main/java, what is the purpose of the src/main? Why does Eclipse create it?
src/main/java is Maven's standard layout for placement of your Java source codes.
Check http://java.sg/maven-standard-directory-layout/ for a list of standard Maven directories.
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project's license
NOTICE.txt Notices and attributions required by libraries that the project depends on
README.txt Project's readme
For src/main/java to exist src/main/ must first exist so eclipse just shows you all the folders in your project including src/main/
If you want to remove them from your view in package explorer, you can create a filter for the package explorer view and exclude Non-Java elements.
Look for the down arrow in the top right of the package explorer view for the filters option.
You can have other sub-directories under src/main that are not source files.
If you see Maven documentation you need to have resource files under src/main/resources.
Obviously the parent directory src/main needs to be created to create child directories.