Does the Google-Eclipse plugin autogenerate war directory contents? - java

I just created my first Web Application Project using the Google-Eclipse plugin. Amongst other artifacts, it autogenerated a war/ directory with several subdirectories and many files, including:
war/
WEB-INF/
lib/
<Lots of JARs here>
web.xml
appengine-web.xml
etc.
Several times now I've cleared out certain parts of this war/ directory (messing around with buildscripts and other Google-Eclipse plugin features - this is just a test/temp project for getting used to the plugin), and they magically reappear at some point in the future.
I'm wondering if, because I set this up as a Web Application Project (and it is thus managed by the Google-Eclipse plugin), is the plugin trying to preserve the structure of the war/, and as such, continuing to auto-generate any missing files?
If so, why? Exactly (which files/directories) what is it trying to preserve? Can I disable it?
And if not, then I obviously have something else going on here. In which case, has anybody else ever experienced this with the Google-Eclipse plugin, or just Eclipse in general? Thanks in advance.

This plugin only updates war/lib directory by adding dependencies. Actually it just copies jar files when you switch to a another version of Google App Engine SDK.

This should not be a problem.
War folder is the exploded package that later on you need to deploy to Google App Engine.
When you build or deploy file to GAE, this folder will be re-created/updated, and it contains the newly compiled jar and the necessary libs.
Read this.

War folder contains the generated javascript files which are deployed to the app engine.

Related

How to include libraries during war file built in spring project?

I have a spring project and it is running well. The problem is, whenever I perform a new deployment using the war file in tomcat, I need to manually copy the libraries in the lib folder. I am wondering if there is any way to add those libraries inside the war file so that every time I don't need to waste my time by copying the libraries in the server. It needs to be automatically included from the generated war file.
This answer depends on how you are building your WAR but I assume you are using one of the popular build tools for Java. Given that your war does not have a populated lib folder I'm assuming you have either not configured the right plugins for these build tools or you are compiling and managing your classpath from the command line like a madman. If the later is the case then I highly suggest you start using a build tool for your projects (All IDE's do this by default), if the former is the case I refer you to the individual pages for the plugins:
Maven:
https://maven.apache.org/plugins/maven-war-plugin/index.html
The war plugin does this by default.
Gradle: https://docs.gradle.org/current/userguide/war_plugin.html
The War plugin for Gradle also does this by default.
Ant: https://ant.apache.org/manual/Tasks/war.html
A glossary reading for the Ant tasks did not reveal if it did so by default but I'm assuming it does.

usage and significance of .Classpath in Application EAR

I am currently working on an EAR application which has a WEB project and EJB project in it.
To work on eclipse with local set up i do so many build path setups and all.
All these buildpaths show up in .classpath of the project.
Now when i export the EAR and deploy on Server everything works on server.
My doubt is how does server know about my local system paths which are present in .classpath of my project.
Does it mean .classpath has no significance at runtime?
Please explain.
.classpath file is eclipse specific, it will not be bundled with the EAR. Eclipse uses it to set the classpath for the project.
An EAR has a well defined structure and Servlet container understands that structure, using it's knowledge it prods around in the EAR file and extracts classes to load in the runtime.
Obviously server doesn't have any knowledge of your local environment. An EAR (or WAR or JAR) file is a simple archive file (with some specification or the file order and all). You can unzip it using any utility (something like 7zip). Check the structure of the packed EAR, that will give you a better understanding of what goes to your server.

Approach for developing client side web libraries (e.g. webjars)

I have a number of internal projects that are essentially client-side web assets that I'd like to distribute to colleagues as webjars via our repository manager. So far the development process has been:
Build an example webapp that includes the web assets I'd like to distribute and test.
Create a separate project with copies of the assets located in src/main/resources/META-INF/resources rather than src/main/webapp; set <packaging> to jar rather than war in pom.xml. Build and deploy the jar artifact to the repository manager.
Create a third project as a testbed to verify that everything works correctly when the jar file from (2) is included as a project dependency.
I'd like to combine (1) and (2) so that I can test and release from a single project. I'll need to get Maven to selectively move the distributable assets to the right locations. Seems like I'd also need a way to switch <packaging> as well. Any suggestions on how to do this or better alternatives?
Unfortunately I don't think there is a good way to deal with this when using WAR-based webapps because WAR files aren't like JAR files. If you were using a non-WAR-based web framework (Play Framework, Dropwizard, etc) then you could definitely keep JAR packaging and have both the static assets and the testing app in a single JAR.

Hot-deploy JSPs in web-fragment using Eclipse and Tomcat (Servlet 3.0)

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.

How to organize gae projects in eclipse

I try to find the way to organize a GAE with several projects within Eclipse using the Google plugin for GAE:
The Web App project (a WebApp project) containing the GAE web application.
A Java project with data access
A Java project with utility classes
My problem here is how to link things together. I want to add the two Java projects in both build and execution paths. Since a Web App project follows the JavaEE structure, only what is specified in the WEB-INF/lib directory is taken into account.
I would like to find out how to simulate a Jar file in this directory based on a Java project present in the Eclipse workspace based on what the Google Eclipse plugin for GAE provides.
I saw something that seems to be related in the WebApp project properties Google > Web Application, section "Suppress warnings about these build path entries being outside of WEB-INF/lib".
For the GAE web application to run then you'll need the classes or a jar from the projects you want to include in the WEB-INF/classes or WEB-INF/lib folders respectively.
One way would be to build your data and utility projects and put the resulting jars in the WEB-INF/lib folder. You can then then reference those jars as libraries from your web app and all should be fine. Of course that's a bit tiresome to do manually, so you should probably check out some dependency management tools. From personal experience Ivy and IvyDE were easy to get into and should cover your needs although Maven and others have their strengths.
Another way that is a easier (but less structured) is to used linked source folders in your build path (to the source folders for your data and utility projects). In such way Eclipse will build those sub projects to WEB-INF/classes and build and execution should work similarly.

Categories