As described into question title, I've an Eclipse Java EE Web Application project. Into WebContent folder I've some files and subfolder in which there are .DS_store OsX system files that cause some problem because they are always included when I export into war file.
I know that there is a way for excluding a file or folder but only into src folder, not into WebContent!
Any ideas?
Regards
Why not remove the from (delete or just move to another folder) if they shouldnt be in your webcontent folder?
Otherwise you could use the Deployment Assembly settings. Open it from your project properties, and remove the top WebContent and add what you really want to get packaged.
Also you can exclude the files/folder by setting a resource filter. Add a filter... as shown below:
you can use war task of ant. say you located your ant build file directly inside your web-project then the following work for you which excludes folder .DS_store and all its contents from exported war file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="war" name="TestWeb">
<target description="export-war" name="war">
<war destfile="/home/guest/Desktop/TestWeb1.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent">
<exclude name="**/.DS_store/**"/>
</fileset>
<classes dir="build" />
</war>
</target>
</project>
I am trying to use JRebel and having problem while publishing the files like xhtml under src/main/webapp folder. I can do hot replacement of classes, it is working.
I am using Eclipse Helios, Tomcat 7 and JRebel Eclipse plug-in. Also i am using WTP.
I checked the tmp0\wtpwebapps\myapp-web directory. rebel.xml exists at WEB-INF/classes folder. So it should be ok.
Here is my rebel.xml
<classpath>
<dir name="C:/Users/user/workspace/myapp/myapp-web/target/test-classes">
</dir>
<dir name="C:/Users/user/workspace/myapp/myapp-web/target/classes">
</dir>
</classpath>
<web>
<link target="/">
<dir name="C:/Users/user/workspace/myapp/myapp-web/src/main/webapp">
</dir>
</link>
</web>
I tried a lot but could not understand why JRebel does not hot deploy webapp folder. I could not find anything useful at jrebel.log file.
First of all, remote the test-classes folder from rebel.xml classpath definition - you may have strage effects with that one.
When the application server starts, do you see JRebel: the directory 'blah' is being monitored" messages at the console?
Send the jrebel.log to support - they will help. It can be some minor version difference of the Tomcat instance.
Im developing application on top of Netbeans Platform.
In NetBeans IDE it is possible to choose different Netbeans Platform (it can be added under
NetBeans Platform Manager), but i cant find option/property to change default selection.
Is this even supported on Netbeans IDE?
I can't see a way to do this using the default ant based system. However if you use the maven based approach then it is a simple as editing the pom.xml
Solution for ANT based Nb Platform application is to modify ant build file to create custom properties before building application (separate modules). In this solution I create new properties file and fix the pointer in platform properties file to point to it. This file is later imported before building each module.
1) Create/Modify platform-private.properties to set user.properties.file to your custom one (i.e nbproject/private/build.properties). This file is later used to configure properties when building separate modules.
2) Create new user.properties.file (build.properties) and set nbplatform.default.harness.dir and nbplatform.default.netbeans.dest.dir to correct values (those parameters points to folder where nb platform is located - in my case it is located in project basedir under ./nbrc folder)
<project name="..." basedir=".">
<!-- Basedir property must be converted to use forward slashes (for windows machines) -->
<path id="basedir.path">
<pathelement path="${basedir}" />
</path>
<pathconvert targetos="unix" property="basedir.unix" refid="basedir.path"/>
<!-- Initialize path to netbeans platform [located in nbrc folder in project root directory -->
<mkdir dir="nbproject/private"/>
<echo file="nbproject/private/platform-private.properties">user.properties.file=${basedir.unix}/nbproject/private/build.properties${line.separator}</echo>
<echo file="nbproject/private/build.properties">nbplatform.default.harness.dir=${nbplatform.default.netbeans.dest.dir}/harness${line.separator}</echo>
<echo file="nbproject/private/build.properties" append="true">nbplatform.default.netbeans.dest.dir=${basedir.unix}/nbrc${line.separator} </echo>
<!-- .. -->
</project> `
During development I frequently have to deploy a large war-file (~45 MB) to a remote test server, normally I copy the file with scp to the server.
The WEB-INF/lib folder makes up the largest part of the war file, which includes all the required libraries (spring, apache-cxf, hibernate,...).
Now I'm searching for an fast and easy a way to redeploy only my altered files.
And how can I determine which packages are really needed by the webapp, because spring and apache-cxf comes with a lot of libs, I'm sure I don't need all of them.
When you deploy a .war, the first thing Tomcat does is to unpack that file into its webapps directory, in a subdirectory with the same name as your .war.
During development, you obviously have access to your .class files, the .jar files, configuration files and whatever else eventually goes into your .war. You can easily establish a small subset of files affected by your changes. Figure that out, and then use a script or an ant task or whatever to copy just that small handful of files straight into the webapps/yourapp directory on the server.
To see your changes take effect, you'll need to re-start your application. If Tomcat is in development mode, one easy way to force a reload (and restart, of course) is to update WEB-INF/web.xml. So have your deployment process touch that file or otherwise update it in a way that will give it a new timestamp, scp that over too (preferrably as the last of the files you update) and you should have a quick and easy reload.
What I do is exclude WEB-INF/lib/*.jar files from the WAR and reassemble on the server side. In my case, this trims a 60MB WAR down to 250k which allows for really fast deployment.
The <exclude name="**/lib/*.jar"/> command is what excludes the jar's (see last code snippet for ANT build)
On the server side, it's quite easy to assemble a fully populated WAR from the trimmed WAR:
unzip/explode the trimmed WAR that was created by the ANT script below
copy the server repository jar files into the exploded WEB-INF/lib
zip is all up into a new (large) WAR.
deploy as usual.
For example:
unzip ../myapp.trimmed.war
mkdir WEB-INF/lib
cp ../war_lib_repository/* WEB-INF/lib
zip -r ../myapp.war .
Maybe not the most elegant solution, but it saves time on frequent deployment of large WAR's. I'd like to be able to do this with Maven so if anyone has suggestions, please let me know.
ANT build.xml:
<property file="build.properties"/>
<property name="war.name" value="myapp.trimmedwar"/>
<property name="deploy.path" value="deploy"/>
<property name="src.dir" value="src"/>
<property name="config.dir" value="config"/>
<property name="web.dir" value="WebContent"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="${war.name}"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- other classes to include -->
<fileset dir="${birt.runtime}/ReportEngine/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" debug="true" deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="createwar" depends="build" description="Create a trimmed WAR file (/lib/*.jar) excluded for size">
<!-- copy the hibernate config file -->
<copy todir="${web.dir}/WEB-INF/classes">
<!-- copy hibernate configs -->
<fileset dir="${src.dir}/" includes="**/*.cfg.xml" />
</copy>
<copy todir="${web.dir}/WEB-INF/classes">
<fileset dir="${src.dir}/" includes="**/*.properties" />
</copy>
<!-- copy hibernate classes -->
<copy todir="${web.dir}/WEB-INF/classes" >
<fileset dir="${src.dir}/" includes="**/*.hbm.xml" />
</copy>
<war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
<!-- exlude the jdbc connector because it's on the server's /lib/common -->
<exclude name="**/mysql-connector*.jar"/>
<!-- exclude these jars because they're already on the server (will be wrapped into the trimmed war at the server) -->
<exclude name="**/lib/*.jar"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
I use rsync to copy my .war from my local machine to production. It usually provides a big speed up, around 8-10 times.
Another option is to use git to store the .war files. When you git push a new .war, only the differences are transferred. Also a big speed up. Some people say that git is not designed to store big files, it gets slow and does not work very well. In fact yes, the repo will grow a lot, but in some cases it could be a good option.
Some numbers: My .war is about 50MB and when I deploy a new version, it only copies about ~4MB instead of uploading a complete new war. Both with git and rsync.
UPDATE: The problem I ran into it's the git repo cannot be cloned after it has several .war versions because it will take forever to create all the deltas and transmit them to the client.
I changed the strategy by uploading the .war files into dropbox. Dropbox also uses kind of rsync and only copies deltas. From the server I wget the .war and re-reploy the app. Hope this helps.
Improving on Rori Stumpf answer, here is a Gradle task for the 'thinning'
war {
archiveName "v1.war"
}
task createThinWar(type: Copy) {
dependsOn 'war'
def tmpFolder = "${buildDir}/tmp/thin"
def outputDir = "${buildDir}/libs"
// Extract the war (zip) contents
from zipTree("${outputDir}/v1.war")
into "${tmpFolder}/v1"
doLast {
// Extracting the war third party libraries to a separate dir
ant.move(file: "${tmpFolder}/v1/WEB-INF/lib", tofile: "${tmpFolder}/v1-libs")
// Zip the third party libraries dir
ant.zip(destfile: "${outputDir}/v1-libs.zip") {
fileset(dir: "${tmpFolder}/v1-libs")
}
// Finally zip the thinned war back
ant.zip(destfile: "${outputDir}/v1-thin.war") {
fileset(dir: "${tmpFolder}/v1")
}
}
}
This will generate v1-thin.war (weighting less then 1mb), and a libs zip.
deploy the thin war to the server (and reconstruct the libs there), and deploy the libs zip whenever you modified the versions/add libraries.
I don't think there's a faster way to redeploy only the changes to a WAR file.
If you deploy in exploded fashion you can see what file timestamps have changed and act accordingly, but you'll have to write code to do it.
I don't know if OSGi can be a help here. That would allow you to partition your problem into modules that are more independent and swap-able.
Just curious:
How long does it take now?
Do you use continuous integration to build and deploy?
Is there any easy way to automatically deploy a web service / java web app, etc to a remote tomcat server? currently i have to manually copy the .war file.
Personally, I add a "deploy" target in build.xml that contains an <scp> tag to transfer the war file.
UPDATE:
Here is an example:
<target name="deploy" depends="dist">
<scp todir="${user.name}#www.myserver.com:tomcat-base/webapps/"
keyfile="${user.home}/.ssh/myserver.key"
passphrase="BlaBlaBla" trust="true">
<fileset dir="dist" includes="myapp.war"/>
</scp>
</target>