Deployment of war file on Tomcat - java

Is there a way to deploy a given war file on Tomcat server? I want to do this without using the web interface.

There are several ways to deploy a Tomcat webapp:
Dropping into $CATALINA_HOME/webapps, as was already mentioned.
Using your build scripts to deploy automatically via the manager interface (that comes with Tomcat). Here are the two ways
for Maven: use the tomcat plugin. You don't need to include it in pom.xml, just issue the goal mvn tomcat:deploy, the plugin is included in Maven 2. This assumes several defaults explained in the documentation, you can configure the behaviour in the pom.xml. There are other goals that let you deploy as an exploded archive etc.
for Ant: something like this:
<property name="manager.url" value="http://localhost:8080/manager"/>
<property name="manager.username" value="manager"/>
<property name="manager.password" value="foobar"/>
<!-- Task definitions -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask"/>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
<!-- goals -->
<target name="install" depends="compile" description="Install application to servlet container">
<deploy url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="${app.path}"
localWar="file://${build.home}"/>
</target>
<target name="list" description="List installed applications on servlet container">
<list url="${manager.url}"
username="${manager.username}"
password="${manager.password}"/>
</target>
<target name="reload" depends="compile" description="Reload application on servlet container">
<reload url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="${app.path}"/>
</target>
<target name="remove" description="Remove application on servlet container">
<undeploy url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="${app.path}"/>
</target>
All of those will require you to have a Tomcat user configuration. It lives $CATALINA_BASE/conf/tomcat-users.xml, but since you know already how to use the web interface, I assume you know how to configure the users and passwords.

Just copy the war file into the $TOMCAT_HOME/webapps/ directory. Tomcat will deploy the war file by automatically exploding it. FYI - If you want you can make updates directly to the exploded directory, which is useful for development.

We never use the web interface, don't like it. The wars are dropped in the webapps and server.xml edited as necessary. You need to bounce it if you edit the server.xml, but the war file should be picked up automagically. We generally delete the directory expanded from the war first so there is no confusion from where the components came.

you can edit the conf/server.xml and add an entry like this pointing to your war directory
<Context path="/strutsDisplayTag"
reloadable="true"
docBase="C:\work\learn\jsp\strutsDisplayTag"
workDir="C:\work\learn\jsp\strutsDisplayTag\work" />
ELSE
you can copy your .WAR file to the webapps directory of tomcat.

The Tomcat Client Deployer Package looks to be what you need to deploy to a remote server from the command line. From the page:
This is a package which can be used to validate, compile, compress to .WAR, and deploy web applications to production or development Tomcat servers. It should be noted that this feature uses the Tomcat Manager and as such the target Tomcat server should be running.

You can also try this command-line script for managing tomcat called tomcat-manager. It requires Python, and talks to the manager application included with tomcat via HTTP. You can do stuff from a *nix shell like:
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager/ stop /myapp
and:
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager deploy /myapp ~/src/myapp/myapp.war

Related

WSDL file to Jar File

I have WSDL file URL and I want to create JAR file and need use in another project.
I have try to convert with below scenarios
1.Using wsimport command to Java files and using this java files create maven project as packaging JAR
wsimport -keep -wsdllocation /MyService.wsdl
2.Using ANT build (create build.xml file create target for export JAR)
<target name="dist" depends="compile" description="generate the distribution">
<buildnumber />
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib" />
MyApplication-${version}.${build.number}.jar -->
<jar destfile="${dist}/lib/MyApplication-${version}.${build.number}.jar" basedir="${build}" />
</target>
above both scenarios JAR exported but when I deployed in server getting below Exception
java.lang.NoClassDefFoundError
what I am doing wrong ?
is there any simple way to convert wsdl to Jar?
This Issue occur run time class not found.
I have add new Assembly in Eclipse -> specific project -> Web Deployment Assembly
select specific JAR,WAR,RAR or ZIP file from path and set.
and test again after this solved this issue.

How to add security permissions in build.xml using Ant Web Start

I am not very familiar with java build tools such as Ant. We have an old java web start application and now with the new security requirements for RIAs I have to add a security tag to my build.xml But I can't figure out how to do it. I am using ant deploy to build my app. And I am also using ant-jnlp-war (I really can't figure out where this ant-jnlp-war is used) The relevant part of my build.xml is as the following:
<target name="pack" depends="buildinfo,dist,sign">
<jw:jnlpwar
tofile="${war}/lmc.war"
title="Company Management Console"
vendor="Company Teknoloji"
codebase="dummy"
signStorepass="secret"
signAlias="labris">
<jw:description>Company Management Console</jw:description>
<jw:description kind="short">LMC</jw:description>
<jw:shortcut desktop="true" menu="true" submenu="Company Management Console"/>
<jw:j2se minVersion="1.5" args="-Xmx128M" />
<lib dir="${dist}/lib">
<include name="**/*.jar"/>
<exclude name="client.jar"/>
</lib>
<lib dir="${dist}/modules">
<include name="**/*.jar"/>
</lib>
<jw:application mainclass="com.idealteknoloji.lmc.client.ClientManager" jar="${dist}/lib/client.jar"/>
</jw:jnlpwar>
<exec executable="./make-client-packages"/>
</target>
How and where can I add the security attribute as sandbox.
Let's clarify...
Ant-jnlp-war just create war which allow you to distribute your application to clients and contains your jar that means that you should have jar before call ant-jnlp-war.
New security requirements for RIA related to jar because you need to specify in META-INF/MANIFEST.MF from which site application could be distributed:
Manifest Attributes
Permissions – Introduced in 7u25, and required as of 7u51. Indicates if the RIA should run within the sandbox or require full-permissions.
Codebase – Introduced in 7u25 and optional/encouraged as of 7u51. Points to the known location of the hosted code (e.g. intranet.example.com).
As we clarify you don't need to change ant-jnlp-war you just need to have correct MANIFEST.MF within your jar.
Here you have two options:
use Ant task to create MANIFEST.MF like and configure it, example:
<jar destfile="test.jar" basedir=".">
<include name="build"/>
<manifest>
<attribute name="Permissions" value="sandbox">
<attribute name="Codebase" value="example.com">
</manifest>
</jar>
create by hand MANIFEST.MF and put to your jar under folder META-INF
Manifest-Version: 1.0
Created-By: 1.7.0_51
Permissions: sandbox
Codebase: www.java.com

Publish a .war directly from eclipse to a remote web server (FTP, SSH)

I need publish a .war directly from eclipse to a remote web server.
Access available via SSH/FTP
is there plugin/ preferred method for that?
Thanks
Inorder to create and publish a war file directly from eclipse to a webserver you have to do following changes in build.xml file. First create a war file.
<!-- Create Jar File -->
<target name="buildJar" depends="build">
<jar destfile="${jarDir}/${jarFile}" basedir="${jarClassdir}">
<zipfileset dir="${base.dir}" prefix="META-INF" includes="weblogic-ejb-jar.xml" />
</jar>
</target>
<!-- Create War File -->
<target name="buildWar" depends="buildJar">
<war destfile="${warDir}/${warFile}" webxml="${web}/WEB-INF/web.xml">
<fileset dir="${web}" />
<classes dir="${warClassdir}" />
</war>
</target>
Now add following code to deploy it automatically on the server
<target name="deploy" depends="undeploy">
<echo>Deploying...</echo>
<wldeploy action="deploy" name="${deploy.name}" source="${deploy.source}" user="${wls.username}"
nostage="true" password="${wls.password}" verbose="true" adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>
Here you have to provide username, password and all the required fields and it should work.
For uploading a war file directly to the dedicated server, you can refer to JSch Library . By using this, you can directly upload files using ssh.

Classes folder instead of jars in Jetty configuration

i'm migrating our web application from Tomcat 7 to Jetty 9. Ant task is used for Jetty startup. Jar files are located under WEB-INF/lib, class files are located under .build/classes.
The question is: is there any way to specify a folder containing class files instead of jars when performing annotations scan?
Below is Ant target configuration being used:
<target name="jetty.run">
<jetty.run tempDirectory="jetty-temp">
<webApp war="app" contextpath="/">
<attributes>
<attribute name="org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" value=".*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$"/>
<attribute name="org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern" value=".*classes.*"/>
</attributes>
<classes dir=".build/classes">
<include name="**/*.class" />
</classes>
<!--<lib dir=".build/classes">
<include name="**/*.class" />
</lib>-->
</webApp>
<connectors>
<connector port="8090"/>
<connector port="80"/>
</connectors>
</jetty.run>
</target>
I've tried specifying classes element, but it seems to be ignored (.build folder resides at the same location where build.xml is). So the application code jar has to be built and copied to WEB-INF/lib in order for the application to start properly.
Jars reside in a standard location, but classes don't. Could this somehow cause this?
I'd be grateful for any help.
Thanks,
Vitaliy.
I think you should open a bug on jetty for this: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Jetty
The jetty-ant integration will add the onto the classpath, but unfortunately it won't scan them for annotations.
If you upgraded to jetty-9.1.0.M0, then you could try specifying the classes dir instead as , as we implemented annotation scanning on the extraClasspath with this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=416597. Note however,as Joakim says, that the dir name cannot start with a "." as this denotes a hidden directory.
regards
Jan

JavaFX Application Packaging example needed

I have created a simple application for the maintainance of the Contact List.
As I'm a novice to JavaFX, I just want to know about the packaging option.
I want to package the app as StandAlone application where package includes JRE files needed for running the app.
I found this on JavaFX documentation.
Standalone application Packaging
But not getting how to do it?
An example would be really helpful.
Thanks in advance.
I will assume that you are looking to build a Windows standalone application, so you will first need to install WiX to build the msi and Inno to build the exe. You will also need to have ant configured. This example assumes that your directory layout is as follows:
+---classes
+---dist
+---lib
where 'classes' contains the compiled .class files, and the resources that your application needs, 'lib' contains the dependencies jar files, and 'dist' is the target folder which wil contain the application jar file once packed. To pack the application create a build.xml file in the same directory containing:
<project name="JavaFXSample" default="default" basedir="."
xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="default">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath="<here goes the path to java home>/lib/ant-javafx.jar"/>
<fx:jar destfile="dist/example.jar">
<fx:application name="Sample JavaFX application" mainClass="me.App"/>
<fx:resources>
<fx:fileset dir="dist" includes="lib/*.jar"/>
</fx:resources>
<fileset dir="classes"/>
</fx:jar>
</target>
</project>
this will create an 'example.jar' file in the dist folder. Now you should check that the 'javafxpackager' tool is included in your path and then call:
javafxpackager -deploy -native -outdir packages -outfile Example -srcdir dist -srcfiles example.jar -appclass <your main class> -name "Example" -title "JavaFX Example demo"
this will create a layout containing the standalone files.

Categories

Resources