we have a java project created with maven with standart folder tree, that generate maven. we put our xml files and log4j propertie files in resources folder which locates in one level with src folder. in resources folder we have ApplicationSetting.xml and in Eclipse when we write in class "resources/Applications.xml", everythong works nice, but not in Intellij. there we get FileNotFoundException. works only if I'll write "Application/resources/ApplicationSetting.xml". is there any way to write file path as in eclipse. in our team somebody uses eclipse, others intellij.
EDIT:
Folder structure is:
Application
resources
src
main
java
test
the project name in BackEnd and in it we have 4 modules: Application, Configuration, DataLogic and BusinessLogic. In "Edit Configuration" of Intellij working directory is BackEnd, classpath module is Application
Ideal maven structure should be :
src
-main
-java
-resources
-test
-java
-resources
One disadvantage of your folder structure is manual path setting for your resources
and
there is no separation between your source resources and test resources.
Related
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.
I have maven project with three modules. The project structure is below:
- rootProject
-module1
-module2
-module3
simple folder -> -templates
-templatefile.txt
Can I get templatefile.txt from templates folder?
I tried this but is not working:
getClass().getResourceAsStream("templatefile.txt");
and
getClass().getResourceAsStream("/templates/templatefile.txt");
but it does not work to me.
Your question suggests that you have a parent project and three children and that you have created the templates directory at the same level as the child module directories. This would mean that the templates directory is not on the classpath for either the rootProject or any of the child modules.
The convention for a Maven project is that non Java resources should be located in src/main/resources. Anything placed in this directory will be on your project's classpath.
So, move the templates directory into src/main/resources.
I am configuring Jenkins (using Maven integration) for the first time. I am liking it but it is not very smooth.
My project has the following structure
Repository 1
-View
-Model
-Business
Repository 2
-Widget library
In this widget library, I have the following file tree:
-root
-src
-com
-example
-file1.java
-file2.java
-file3.java
-widget1.html
-widget2.html
-widget3.html
My build gets downloaded, compile and a war is generated. It also gets deployed to my remote server and I am very happy about it.
Unfortunately, my project still doesn't open because the widget1.html, widget2.html and widget3.html are missing.
If I unzip my war file and my WidgetLibrary.jar, the .java classes are included there, but the .html are not.
Is there any way to make Maven include all the files in the project?
Maven is driven by convention, so I would speculate that the problem is you're not using the Maven standard directory layout.
In general, your project should look like:
src/
main/
java/
com/example/File.java
resources/
file.html
test/
java/
com/example/TestFile.java
resources/
testResource.txt
This should be invariant of whether it's you or Jenkins building it.
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.
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.