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.
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 a web application. I have created a war file out of the "export" option from Eclipse. However, the war file only contains the META-INF and the WEB-INF folders. There are no .java or .class files at all.
I also tried another method using the Maven "clean install" goals. This one also gives me the exact problem as above. Where am I going wrong? Can someone help me out?
Thanks.
Please chcek if you have your code in default src path for maven (src\main\java)
If your project is an Eclipse project you need to make sure you created it as a 'Dynamic Web Project' so Eclipse attaches the right Facets so it knows how to build the .war.
If it's a maven project, you at least include
<packaging>war</packaging>
so Maven knows how to package your app.
If you run 'mvn package', assuming your pom.xml is configured correctly, you should get a .war file created in the target dir.
Sounds like something is not configured right - can you share more info about your source project structure and how it is configured?
I have a project set up like this:
/parent
/core
/src/main/
/resources/META-INF/
web-fragment.xml
/resources/jsp/
fragment.jsp
/java/
FragmentTest.java
/web
/src/main/
/webapp/
/WEB-INF/web.xml
/jsps/
parent.jsp
/java/
ParentTest.java
the 'core' compiles to a .jar within the .war.
However, when deploying this to Tomcat, with debug enabled, I can edit parent.jsp and it will hot deploy, however if I update fragment.jsp then it will not, and I have to rebuild/redeploy/etc.
However, any changes to the .java in either project will hot-deploy successfully.
Is anyone aware of any configurations, etc. that may be missing to get web-fragment JSPs to hot deploy?
Thanks!
I have the same situation. I have test-web (your parent) and test-web-fragment (your core). I resolved them in the following way:
In the /test-web -> Properties -> Deployment Assembly I added the Fileset rule that points to /test-web-fragment/src/main/resources/META-INF/resources (See the screenshots below).
When I change something in a page from fragment, the eclipse builder copies it to /test-web/src/main/webapp. After that I do a right click to test-web in app server and click Full Publish and I have to the server my changes. This trick I use in the development mode. When I make the build for production I use maven, without this rule.
Your project structure confuses me a bit. We always place JSPs in /src/main/webapp and sub folders therein. I can very well imagine this to be the source of your problem.
You will be able to hot deploy both JSPs and Java files if you do the following:
Separate your web fragment project into two different projects and reference them from your main Web applications:
One containing all your Java source files (this project has to be a Web Fragment). This will be packed as a JAR file and you will be able to hot deploy Java files as you're currently doing
Another project, a Dynamic Web Project, containing all your static / JSP files under the WebContent folder. This will be deployed unpacked and will allow you to hot deploy everything under WebContent folder
There could be a better option than this one, but at least you will be able to work properly until you find something better.
I have a java web application name webapp,when I export it to a war,the source codes will be compiled to the WEB-INF/classes.
Now I want these classed be compressed to a jar,and put into the WEB-INF/lib.
I have tried this:
create a new java project named webapp_jar.
Copy all the source codes under the webapp/src to the webapp_jar/src,configurate the build path to make the project work.
Add the webapp_jar reference to webapp project.
However ,when I run the webapp,it seems that the classes defined at webapp_jar can not be found.
Is this possible?
BTW,I use the eclipse ee ide.
have you try ant https://ant.apache.org/ ?
you could make a jar and copy it to folder you want and build the war after.
But , if I anderstand, you would package all the app to a jar ?
I think your webapp can't work without a servlet or two ...
This is really easy to do with maven by creating two subject projects, one to build the war, and the other as a jar project and then use the jar project as a dependency on your war project which would put the jar inside the lib directory when packaging the war.
No I use the Web Deployment Assembly settings in eclipse. I worked.
You can find details here.
What is the minimal conventional directory structure for a Java web app? What do I need to put in a build.xml file to get ant to build it and make a WAR file?
My goal is to deploy a Wicket app to Tomcat without using an IDE. I want to do it with only ant and my favourite text editor.
Maybe not the most minimalist possible, but the Tomcat project has an Application Developer's Guide with a section on source layout and a sample build.xml
Also, if you are starting a new project, you might want to check out Maven. With Maven, rather than crafting your own build scripts, you adhere to standard layout to do stuff, and then Maven figures out all the rest. It also manages dependencies, including its own. Learning curve is a bit steep, though.
Ours look like this:
web/
web/WEB-INF/ (sometimes we use a conf/ dir at the top level but this is minimal)
src/
lib/
The build.xml has three targets:
jsp: copies everything from web/ into the tomcat webapp folder and from lib/ into WEB-INF/lib
compile: compiles everything from src/ into WEB-INF/classes in the webapp
war: runs compile, jsp, and then zips the contents of the tomcat webapp into a warfile
This structure is a little bit informal and you can do it more cleanly by having a separate build directory for the warfile, and/or a separate compile directory, etc. Some people don't like the idea of deploying directly to the webapp instead of building a war first. But to get something up and running quickly, the above will do nicely.
You should check out maven. It's really complicated, but to build a war file it's simple, and there are plugins that will deploy the war to tomcat.