I'm following a tutorial to set up a skeleton application for tomcat :
http://maestric.com/doc/java/spring/setup#build_files
But I don't understand how build.properties and build.xml actually works.
I'm using windows XP and copied the following even though the required directory doesn't exist:
appserver.home=/usr/share/tomcat5.5
appserver.lib=${appserver.home}/common/lib
Really confused now:(
Tomcat doesn't use the build.xml and the build.properties files, these are for Ant which is a tool to automate the build of the application. The script shown in this tutorial is pretty basic, it defines 2 targets to compile sources and to clean compiled classes. And you would use them like this:
ant build
or
ant clean
The appserver.lib property is used to build the class path required to compile sources. It is derived from the root of your Tomcat installation directory and is used to find the JAR for the Servlet API that you need to compile sources. If you decide to use this Ant script, you should update the appserver.home property to match your install. For example:
appserver.home=c:/apps/tomcat5.5
appserver.lib=${appserver.home}/common/lib
But to be honest, the whole setup is a bit messy (it's straightforward, but messy):
you shouldn't bundle the servlet-api.jar in WEB-INF/lib as suggested
I don't like to develop directly under Tomcat's webapp directory (but this is maybe subjective).
Related
I have a Tomcat 8 web project that I started in Netbeans.
In Netbeans I setup some Global Libraries that I then added to the project.
Building the project in Netbeans works perfectly.
The problem is when I try to build on a Unix platform using Ant.
I use the build.xml file automatically generated by Netbeans, the only difference is that I now have to specify where these "Global" libraries are, I do this as so:
ant -Dlibs.spring-framework-4.0.6.classpath="../libs/spring-framework-4.0.6.RELEASE" clean dist
This however results in these kinds of errors:
error: package org.springframework.beans.factory does not exist
If I go and look inside the build folder in web/WEB-INF/lib, the jar is there and if I look inside it I do find the org.springframework.beans.factory class.
If I run ant in debug mode it clearly states that is copying over the libs:
[copy] Copying /libs/spring-framework-4.0.6.RELEASE/spring-beans-4.0.6.RELEASE.jar to /App/build/web/WEB-INF/lib/spring-beans-4.0.6.RELEASE.jar
As I understand it, the WEB-INF/lib directory is on the classpath by default. Is this not what happens and do I need to specifically tell it to add this directory to the classpath?
Found the solution myself, it turns out I have to specifically reference each and every jar, it is not enough to reference the directory.
So this:
ant -Dlibs.spring-framework-4.0.6.classpath="../libs/spring-framework-4.0.6.RELEASE" clean dist
Should have been this:
ant -Dlibs.spring-framework-4.0.6.classpath="../libs/spring-framework-4.0.6.RELEASE/spring-aop-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-aspects-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-beans-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-context-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-context-support-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-core-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-expression-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-framework-bom-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-instrument-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-instrument-tomcat-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-jdbc-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-jms-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-messaging-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-orm-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-oxm-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-test-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-tx-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-web-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-webmvc-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-webmvc-portlet-4.0.6.RELEASE.jar:../libs/spring-framework-4.0.6.RELEASE/spring-websocket-4.0.6.RELEASE.jar" clean dist
I have a plain Java project (not a plugin project) which I want to add to a classpath of a eclipse plugin which I am developing. But in web projects I can add that project as a build path and it works fine. But I tried same thing in eclipse plugin, I am able to compile successfully, but at run time I am getting java.lang.ClassNotFoundException.
I know OSGi quite well and I know how to add OSGi into an classpath (using export-packages) but what I want is to add Standard, non-osgi project into an classpath, so that I wont' get runtime errors. Is there anyway I can achieve this?
I can export project as a jar file or make it as a plugin project and it would work fine. But that's not my option currently because, still that API is in pre-alpha stage, and there would be lot of changes going on. So I am trying to avoid pain of exporting it as jar file everytime. Is there any option for me other than this?
I have a similar situation: I want non-OSGi Maven dependencies integrated into the classpath of my plugin. I succeeded with a roundabout solution, which I think is the best I could get.
I have a build step outside of Eclipse where I copy the class files of the dependency into the plugin's lib folder. The lib folder is specified in MANIFEST.MF as an entry in Bundle-ClassPath and (here comes the hack) as a source folder in build.properties. That was the only way to make the plugin work both when launched from within Eclipse and when exported.
I am struggeling with this for a while.
I am using Spring3.1 in a standalone env. I have resources files which I need to add into the classpath (applicationXML). In eclipse it's a known and easy way. Now I am trying to deploy my application to a standalone env on linux using Daemon (commons-daemon-1.0.3.jar).
How can I add resources files there to the classpath?
One thing you can do is use the Maven Shade plugin. This is used to create a SuperJAR of everything in your build profile — dependent JARs from Apache and Spring, as well as your own code. The Shade Plugin can that add a Classpath entry of "." into the Manifest of the SuperJAR, this is precisely how you will be able to run the Main class of the SuperJAR, but have the classloader look in both a local directory as well as a JAR for all your components.
You'll have to adjust your build a bit so that things like log4j.properties and application-context.xml, and other files you wish to have sysadmins/customers modifer after build are kept out of the resources/path — otherwise they will get baked into the build.
You might look at my source code here http://sourceforge.net/projects/jee2pctest/. The client driver code provides an excellent example of how to use the Maven Shade plugin to create a directly executable JAR with external properties files.The magic is mainly in the pom.xml file. One Caveat, I am using the Maven build tooling, if you are still on ANT using using your IDE's built-in packager, then you might have some work cut out.
I have a running Java GWT application, that I can compile using Eclipse.
Now I wan't to also be able to build this application from the command line using ant.
As of my understanding I therefore need a build.xml file.
I used the webAppCreator tool, that comes with the SDK to create this build.xml file and adapted it to my needs and got it working.
But how do I tell Eclipse now to automatically update the build.xml file upon code changes?
I know it is possible for it works in projects created with webAppCreator. But I just copied the build.xml to another project. So what do I need to adapt? Or where do I need to set up the link to the build.xml?
You could use Ant4Eclipse to get the Eclipse classpath into your ant build file. That's probably only part of the solution you're looking for... I'm not sure, how useful this will actually be when used together with a GWT project (do you want automatic copying of the libraries to WEB-INF/lib, too? Etc...)
What are the best practices (and enabling tools) to deploy Java standalone applications along with any required jar dependencies, config files, and launch scripts?
Are there any Maven plugins that easies publishing binary releases, so that users don't need to use maven for example?
Are there any Maven plugins that easies publishing binary releases, so that users don't need to use maven for example?
Use the Maven Assembly Plugin to create a binary distribution as zip/tar.gz/tar.bz2 of your project. This plugin is extremely flexible - at the price of some complexity - and you can do almost anything you want. Then deploy (in the maven sense) the produced artifact, upload it somewhere, etc.
As for dependency, I just use maven dependency copy plugin and copy all dependencies into a ./lib folder, and supply a launch script that uses the class path wildcard (that way you can change your dependencies as much as you want and don't have to change the launch script). As for configuration files, I put it in a ./config folder and again include it in my app's classpath in the launch script (The former admittedly only works for > java 1.6).
So in the end almost all my app has the following structure:
mystuff.jar launch.sh
./lib
./config
Then I'll just zip up the whole thing and give it to my users. The whole process is probably easy to automate using maven, but I confess that I do it by hand :p
If you prefer and the licenses permit, you could also just bundle all dependencies into a single jar (with expanded dependencies inside) using the assembly plugin. This tends to make the jar bulky and giving the users an updated app. more difficult. Also I had issues with it several time because of class files getting overwritten or something so I personally stick to the ./lib folder.
There's launch4j, which, if you can get it to work, will bundle up a Java app into an executable for your platform.
If your deployment target supports RPM files, I strongly suggest you investigate the rpm-maven-plugin. It allows you to easily map your project artifacts , including dependencies, to a RPM package.
I've been using it with great success to medium-scale application deployment.
You can use Oracle's ant or maven scripts:
http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
The above will not only compile your code and create jar files, but it will also create binary executable (windows exe file or Mac app file). It can also create native installers. In addition it lets you include JVM with your distribution so the end use doesn't need to install Java.
Take a look at the Appassembler Maven Plugin. You may also want to combine it with the Assembly Maven Plugin.
Use the appassembler plugin to generate a set of "programs" by specifying executable names and main classes. You can also have it prepend and create an etc directory in which you can add configuration files.
If generating the directory with the start-up scripts and directory of binary files isn't enough, you can use the assembly plugin to copy over additional files (say your configuration files) into the appropriate directory and/or package your application into an archive.