I am working with GWT and I have some issues with the images. I need images outside my WAR file and, In order to make them visible in the application, I must put them inside the "target" folder ( I am using maven as well). The problem is that the target folder by definition is deleted every time recompile the project. This issue happens only in hosted mode, because when I deploy the application on Tomcat I can just change the server.xml adding the following statement
and it should read correctly images outside my WAR file(not tried yet due to another problem I have)
Can anybody give me some suggestions?
What is the directory structure of your maven project? Why is there a requirement for you to put the images in the target folder? Typically in a Maven project the items you put in the src/main/resources/static such as images end up in the built artifact.
Related
I am developing a Java application with Eclipse and under Apache Tomcat.
when I load an image it puts it in this directory : C:\wamp\www.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myproject\.
If I want to display the image I should refresh the directory (images) in Eclipse.
Does that happen only when I use Eclipse? And if I deploy the project, will the image be loaded always in this folder or in any folder?
When you create a Tomcat project with Eclipse, you have a special folder where you can copy your web resources to, e.g. images, CSS files, and the like.
When you deploy your web application, Eclipse will package it correctly to make sure the images and CSS get copied over.
Make sure you use relative paths, not absolute paths. Also I would recommend you write a maven script or ant script to handle packaging and deployment instead of using Eclipse. It is cleaner and you understand better how things work.
Using Tomcat, I build a new WAR via Maven. Then I copy the output WAR to $TOMCAT_HOME/webapps. Then, ROOT.war becomes exploded and ROOT appears.
If I modify ROOT/style/core.css, will those changes be picked up by my web app at run-time when I re-run $TOMCAT_HOME/bin/catalina.sh start?
Note, this is a GWT application.
If you change files in the exploded WAR directory inside your webapps folder, the changes will immediately be visible. You don't even have to restart Tomcat for this to work.
I think there is a dev mode for GWT that will load the CSS as a static file distinct from the rest of the app. This wold enable normal editing of the file on disk to be seen in your gui.
https://developers.google.com/web-toolkit/doc/latest/DevGuideCompilingAndDebugging#DevGuideDevMode
In my workspace, I have my main project and it uses several jars. I need to make changes in one of the jars. I added the source for that jar to my workspace and I make the change, create a new jar at the command line, copy it over to my main project, bounce app server and try it out. Is there a way to instead point my project at the jar source rather than the jar file? I'd expect to change the jar source, Eclipse would auto build like it does my main project, and I'd only have to restart my app server to test.
You can add external jars, then you can build the jar, safe it somewhere accessible by your app server and restart the server, it will use the new jar and everything should be fine.
For a bigger scope there are many solutions using maven for example to build more then one Project at a time and merge them like needed, but that would be to much for a single jar.
I want to place development web.xml in another folder in eclipse.
This can be done using the Deployment Assembly properties. Right click on the web project, choose Properties, and then navigate to the Deployment Assembly panel. Remove the /WebContent entry (pointing to /) and then add another entry, of type Folder. It should be rooted where you want to keep the web.xml, and mapped to /.
This technique can be extended to make Eclipse work with arbitrary build tool source layouts.
You might want to use Apache Ant
for that purpose. You may define a "conf" directory and place all you config files there, or a resource directory for the same reason.
If haven't use ant for that purpose, I strongly recommend you to do so.
Here is a sample ant build.xml for a web app Sample Build.XML
I'll use Maven myself, but since you're just beginning, Ant would be just fine.
I am using the eclipse builder and not ant.
Actually what i did was that i defined web.xml in another folder. So now I have two web.xml, one for welogic with a lot weblogic specific stuff like filters. And i have another for development which i placed in another folder, in the web project and added this folder to the deployment descriptor for tomcat in eclipse. So now when i deploy the application, the web.xml for tomcat which is in my specified folder owerwrites the web.xml present in web-INF folder(in the deployment directory).
Looks to me a nice workaround.
I'm using Netbeans IDE for developing a web applications, and I've some JARs available in the application server which don't need to be in the WAR (but we need them to compile and run locally).
Is there an option in Netbeans to exclude the JAR file while building the WAR file?
Select the project in the Projects explorer window.
Pick the Project Properties item from the File menu (up in the menubar).
Select the word Libraries from the list on the lefthand side of the dialog that appears.
For each jar/library listed in the Compile-time Libraries list, uncheck those that do not need to be included in your war file.
I found the problem myself. I've all the libraries under my lib folder and added them to the project class path. Since the build is copying the entire content in the project, my library is also copying even though I've unchecked the package check box against the library.
So, don't put the library in your lib folder if you want to exclude that in the WAR built.
Thanks
Santhosh