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.
Related
I am using git with fellow student, now I've noticed that if I load a branch of another student it imports the src folder weirdly.
what could be the problem?
Eclipse is not recognizing your src directory as a source folder, and therefore not displaying the underlying directories as packages.
You need to define the source folders in your project, typically src/main/java and src/test/java (Maven convention).
If someone else's branch uses different source folders than you, then you get this problem when you switch. It might be useful to either follow the same project structure if you work together, or use separate Eclipse projects.
I am learning java and using JetBrains' IntelliJ IDEA as IDE. I am working on a small project which I would like to track via git/GitHub, as I am also learning how to use it.
My question is: where should I place the git directory (i.e. where should the .git folder go)?
As you might be aware, IntelliJ automatically creates the following folder structure when you create a project:
.idea folder created by IntelliJ
out folder containing compiled classes
src folder containing the source code (.java files)
projectName.iml file created by IntelliJ
I am hesitating between putting it in the root folder of the project or in the src folder. My gut feeling would push for the latter, as this is what I'm mostly interested in sharing, but I would like to know what the best practice is.
Generally, You should really keep it in the root folder and simply create .gitignore with all the folders that you are not interested in putting to Your repo.
This is because You really want your root folder to be the git repository, because of practical reasons. If You would keep it in the src folder then you would basically leave out everything that is in the root folder, like for example pom.xml or build.gradle or other files. What is more You would make it harder for other people to use such project, due to the fact that most of the IDEs actually uses the format with src/main and src/test folders.
The best practice is to put root directory to git and list everything you don't want to push to git in .gitignore file. You can use ay open source java project as example, i.e. https://github.com/apache/jmeter
You can see the .gitignore content: https://github.com/apache/jmeter/blob/trunk/.gitignore
I'm converting an old Ant build into a Maven project and I would like to maintain the exact structure of the resulting War file that they created using Ant. Here is the desired structure of the War file.
Here is the structure of the project before it is compiled and packaged.
I'm having trouble figuring out how to create a jar of example.java and place it into a folder called applet which is at the same level as the other folders from the web folder. I can restructure the project any way I like but I have to keep the resulting war file's structure the same. So how do you create a jar file and a war file and place the jar file inside the war?
Note: I've been trying to use this example here, How to create a jar from part of my project that is packaged as a war, but the structure is so different I'm having trouble getting it to be exactly what I'm after.
P.S. I'm also curious as to why they set up their Ant build this way to begin with. I mean, what is the point of having the classes packed up in a jar and placed inside the applet folder rather than just putting them in the traditional place inside a war which would would be under WEB-INF/classes/java/com/example/*.class.
The easiest is to move example.java into its own module with jar packaging (i.e. sub project) and then use Maven Dependency Plugin to copy that artifact into the /applet folder before packaging your war.
I have download a sample project and saw the below package structure.
src/main/java
src/main/resources
JRE System Library
Referenced Libraries
src
main
webapp
css
user
WEB-INF
target
Is it a best way to create the package structure. Normally when we create a dynamic project in eclipse it has one src folder and the WebContent folder in project root. The WEB-INF would be under the WebContent. But here we can identify two source folders and instead of WebContent we find webapp under the source folder not in root.
Despite its correct package structure or not i try to create the same in eclipse. But i cant rename the src folder to something like src/main/java know. It gives me an error
Cannot nest source folder "src/main/java" inside source folder "src".
in eclipse when create a dynamic project
This structure is maven based web base project and mostly for maven base project this structure is used, and as for as new conventions Maven is most popular deployment tool, so I myself recommend the maven base architecture.
If maven drives this organization a maven plugin exists, its goal is to generates eclipse projet.
A second plugin (an eclipse plugin) exists to faciltate the integration into eclipse.
The src/main/java folder is an automated updated duplicate of src folder. (These are the build paths configured in your project)
You should edit your files in src and the changes will be updated by eclipse to their symlinks.
First of all, its only one src folder. Eclipse displays them in such a way to make it easier to access different parts of the project. Webapp is main WebApplication Folder which contains all the goodies. The other most important folder is WEB-INF this is folder which is read protected from the client side so, you have your Java Class files and any thing which you want to protect from the client inside this folder. This folder also, contains a lib directory to contain the JAR files. This is the main overlay for the directory structure.
i'm using maven 2.1-SNAPSHOT as eclipse plugin.
My project structure is like this:
src/main/java
-model
-service
-action
src/test/java
empty atm
src/main/resources
empty atm
src/test/resources
empty atm
src/main/webapp
-js
-dojo
-META-INF
-WEB-INF
web.xml
appcontext.xml
struts.xml
index.jsp
I'm having trouble understanding the build process and where to put which file.
I use as Application Server Jetty but i want to deploy my project on tomcat as well
(so i have set up in my pom packaging war).
When i run my project with the maven:install command my target folder looks like this:
myproject.war
war
not relevant
test-classes
empty atm
myproject
js
META-INF
WEB-INF
index.jsp
classes
model
service
action
My problem is that i need in the classes folder my persistence.xml which i have in META-INF. And struts.xml too i guess. I'm not sure about dojo either if it is right there. And honestly i don't know if this structure is right at all. I also dont know how to configure that the output changes.
I hope somebody can help me i really want to understand this process how it should be right, maybe there are even nice ressources to lookup to get
better at these things. Thanks in advance kukudas
I believe files that you want deployed to the classpath go in the resources/ folder.
Take a look at the Maven in 5 Minutes guide, along with the Getting Started guide.
I think you are missing the resources directory under the src/main/webapp directory. Thats where you can put in your properties and config files for hibernate, struts and spring.
That will allow Maven to copy the files over the the classes directory in the WAR.
Hope this helps.