You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Lukasz Piestrzeniewicz <Lu...@ericpol.pl> on 2003/10/24 10:50:53 UTC

Embedding Tomcat with Maven

Hello!

I wonder if anyone has expirience with embedding Tomcat using Maven and
would like to share his knowleadge?

We use Maven in our new project (which is a web application). We would
like to build version of application with embedded Tomcat. The final
archive should contain the application war file, the Catalina core (we
plan to use Tomcat 4.1.27) and all dependices needed by the Catalina.
And of course a tiny bit of Java putting it all together.

What should be the preferred tactics? To place all jars needed by the
Catalina (with Catalina itself) in the Maven repository and use them as
dependices? Or rather use $CATALINA_HOME and maven.xml to copy needed
files by hand (needs unpacked and ready-to-run Tomcat on each
developer's machine)?

BTW. Is there any plugin to build end user distribution containing all
dependices, startup scripts etc. (like to the form Maven itself is
distributed)?

Uberjar is usefull but as you realize its not necesessery what I would
like to give to end user:

"...and then, you know, you run this supa-uberjar with java -jar
xxx-uber.jar..." ;)

-- 
_____________________________________________
Lukasz Piestrzeniewicz
System Engineer
Ericpol Telecom sp. z o.o.
Sienkiewicza 85/87, 90-057 Lodz, Poland
e-mail: lupi@ericpol.pl
mobile: +48 504488735
tel: +48 42 6353619
fax: +48 42 6315555
http://www.ericpol.pl/
_____________________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Embedding Tomcat with Maven

Posted by Lukasz Piestrzeniewicz <Lu...@ericpol.pl>.
Ben Walding wrote:
> Any reason you've chosen Tomcat over Jetty?

Because we know how to embed Tomcat :) But after your suggestion I try
to look around and find more information about Jetty.

> Why would a user care if they ran a supa uber jar vs. unpacking and 
> stuffing around with script files etc.

Standard procedure for almost every program (as far as Java is
considered: Ant, Maven, JBoss etc.):

1. Get the tarball.
2. Unpack it to usual directory.
3. ln -s ~/usual_directory/app_dir/bin/run-script.sh ~/bin/
4. Use every day with simply calling run-script.sh.

(Non)standard procedure when getting uberjar:

1. Oh! Sweet! Only single jar, no documentation, this must be super!
2. ...but how do I run this?
3. So I still need to download the documentation? And it's in separated
    package?!
4. Download the documentation... Read it.
5. Ah... "java -jar xxx-uber.jar"
6. Where to place it? ...I know, I make a special directory for it!!!
7. First run:
    java -jar ~/usual_directory/app_dir/xxx-uber.jar
8. Second run:
    java -jar ~/usual_directory/app_dir/xxx-uber.jar
9. Third run:
    java -jar ~/... blah! I'm must write a script for it!
10.Write run-script.sh
11.Place it in ~/bin/
12.Call run-script.sh.
13.Check why it doesn't work
14.Fix the typos.
15.Use every day with simply calling run-script.sh.

I know this is a sarcastic, but some kind of packaging plugin realy 
would be useful. How is the packaging of Maven done?

And another thing... When embedding Tomcat I need to manualy provide it 
with path to application.war (or unpacked directory). How to do that 
when all is in a single uberjar?

-- 
_____________________________________________
Lukasz Piestrzeniewicz
System Engineer
Ericpol Telecom sp. z o.o.
Sienkiewicza 85/87, 90-057 Lodz, Poland
e-mail: lupi@ericpol.pl
mobile: +48 504488735
tel: +48 42 6353619
fax: +48 42 6315555
http://www.ericpol.pl/
_____________________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Embedding Tomcat with Maven

Posted by Ben Walding <be...@walding.com>.
Any reason you've chosen Tomcat over Jetty?

Why would a user care if they ran a supa uber jar vs. unpacking and 
stuffing around with script files etc.

Lukasz Piestrzeniewicz wrote:

> Hello!
>
> I wonder if anyone has expirience with embedding Tomcat using Maven and
> would like to share his knowleadge?
>
> We use Maven in our new project (which is a web application). We would
> like to build version of application with embedded Tomcat. The final
> archive should contain the application war file, the Catalina core (we
> plan to use Tomcat 4.1.27) and all dependices needed by the Catalina.
> And of course a tiny bit of Java putting it all together.
>
> What should be the preferred tactics? To place all jars needed by the
> Catalina (with Catalina itself) in the Maven repository and use them as
> dependices? Or rather use $CATALINA_HOME and maven.xml to copy needed
> files by hand (needs unpacked and ready-to-run Tomcat on each
> developer's machine)?
>
> BTW. Is there any plugin to build end user distribution containing all
> dependices, startup scripts etc. (like to the form Maven itself is
> distributed)?
>
> Uberjar is usefull but as you realize its not necesessery what I would
> like to give to end user:
>
> "...and then, you know, you run this supa-uberjar with java -jar
> xxx-uber.jar..." ;)
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Embedding Tomcat with Maven

Posted by Paul Libbrecht <pa...@activemath.org>.
Lukasz,

We have been doing this and it's no so hard to collect all jars and make 
it a double-clickable jar...
Here's our maven.xml extract...
You'll note that we call a GUI for that... it makes no sense to make a 
double-clickable jar that's not a GUI, I feel. This class also sets the 
catalina.home system-property (assuming the classloader is a subclass 
URLClassLoader). I simply use logFactor 5 as a GUI... Some authors which 
run their own servers have liked it.

     <jar destFile="target/${fatJarName}">

       <zipfileset src="target/${maven.final.name}.jar"/>
       <j:forEach var="lib" items="${pom.artifacts}">
         <zipfileset src="${lib.file}"/>
       </j:forEach>

       <fileset dir="conf"><include name="log4j.properties"/></fileset>

       <manifest><attribute name="Main-Class" 
value="org.activemath.config.startup.AMMonolithicWithGUI"/></manifest>
        </jar>

       <copy file="target/${fatJarName}"
         todir="."/>

     </goal>


We've even partially also succeeded in running it over JNLP... the 
trouble remaining that you need a home for such things as the work 
directory....
Aside of the things previously mentionned, I got biten by class-loading 
stories. Here's our invoke, basically extracted from the boostrap of 
catalina. (this classloader subtleties allow the boostrap classes of 
tomcat to be invisible to webapps):

       String[] args = new String[] {"start"};
       ClassLoader loader = AMMonolithicWithGUI.class.getClassLoader();
       Class startupClass = loader.loadClass
           ("org.apache.catalina.startup.Catalina");
       Object startupInstance = startupClass.newInstance();
       Method setClassLoaderMethod =
	startupClass.getMethod("setParentClassLoader",
         new Class[] { ClassLoader.class});
       setClassLoaderMethod.invoke(startupInstance, new Object[] 		
	{loader});
       Method processMethod = startupClass.getMethod("process",
	new Class[] {String[].class});
       processMethod.invoke(startupInstance,new Object[] {args});

Hope that helps.

Paul


Lukasz Piestrzeniewicz wrote:
> Hello!
> 
> I wonder if anyone has expirience with embedding Tomcat using Maven and
> would like to share his knowleadge?
> 
> We use Maven in our new project (which is a web application). We would
> like to build version of application with embedded Tomcat. The final
> archive should contain the application war file, the Catalina core (we
> plan to use Tomcat 4.1.27) and all dependices needed by the Catalina.
> And of course a tiny bit of Java putting it all together.
> 
> What should be the preferred tactics? To place all jars needed by the
> Catalina (with Catalina itself) in the Maven repository and use them as
> dependices? Or rather use $CATALINA_HOME and maven.xml to copy needed
> files by hand (needs unpacked and ready-to-run Tomcat on each
> developer's machine)?
> 
> BTW. Is there any plugin to build end user distribution containing all
> dependices, startup scripts etc. (like to the form Maven itself is
> distributed)?
> 
> Uberjar is usefull but as you realize its not necesessery what I would
> like to give to end user:
> 
> "...and then, you know, you run this supa-uberjar with java -jar
> xxx-uber.jar..." ;)
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org