You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Brian Toal <br...@gmail.com> on 2017/10/02 06:02:37 UTC

Re: Building a uber/fat jar

thanks John,

I want to decouple my solution from web.xml completely, so the goal is to
have the container to scan all jars on the classpath and look for Servlet
3.0 annotations and do the necessary (register  servlet context listeners,
filters, servlets, etc).  The container starts, but none of the
corresponding annotations are processed.  I have various jars on the
classpath that contain implementations of the Servlet 3.0 annotation.  I'm
most certain I'm missing the configuration that is required to get Tomcat
to do the scanning and processing, but i'm not aware of what that would
be.  Any ideas what that would I would need to add?

Here's a snippet of what my code looks like so far.  See [1] for full
source.


public void start(ApplicationContext acac) {
try {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
// init http connector
tomcat.getConnector();
File base = new File(".");
Context ctx = tomcat.addContext("", base.getAbsolutePath());
ServletContext servletContext = ctx.getServletContext();
tomcat.start();
tomcat.getServer().await();
} catch (LifecycleException e) {
throw new RuntimeException("Unable to launch tomcat ", e);
}
} [1] -
https://github.com/toaler/container/blob/master/container-webapp-tomcat/src/main/java/container/webapp/tomcat/TomcatWebContainer.java

On Sat, Sep 30, 2017 at 5:50 AM, John D. Ament <jo...@apache.org>
wrote:

> I use Maven for the actual build. I use these dependencies (with
> 9.0.0.M26):
>
>         <dependency>
>             <groupId>org.apache.tomcat.embed</groupId>
>             <artifactId>tomcat-embed-core</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.tomcat.embed</groupId>
>             <artifactId>tomcat-embed-el</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.tomcat</groupId>
>             <artifactId>tomcat-juli</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.tomcat.embed</groupId>
>             <artifactId>tomcat-embed-websocket</artifactId>
>         </dependency>
>
> And use the Capsule Maven Plugin to build the actual runtime (better
> isolation than a shaded JAR):
>
> <plugin>
>     <groupId>com.github.chrisdchristo</groupId>
>     <artifactId>capsule-maven-plugin</artifactId>
>     <version>${capsule.maven.plugin.version}</version>
>     <executions>
>         <execution>
>             <goals>
>                 <goal>build</goal>
>             </goals>
>             <configuration>
>                 <appClass>your.main.class.here</appClass>
>                 <type>fat</type>
>             </configuration>
>         </execution>
>     </executions>
> </plugin>
>
> And then the actual bootstrap would look like this:
> https://paste.apache.org/vVNs (I put it in a paste since it's pretty
> long).
>
> On Sat, Sep 30, 2017 at 4:51 AM Brian Toal <br...@gmail.com> wrote:
>
> > Can someone point me to a example of how to run Tomcat as a embedded
> > application, packaged in a uber jar?  I'm not interested in running via a
> > war.  I've struggled to find a example.
> >
>