Setting up Embedded Tomcat to honor Servlet 3.0 Annotations

2017-10-01 Thread Brian Toal
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).  In the code below, 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.  What code do I need to add to get the container to scan all jars on
the classpath for Servlet 3.0 annotations and register the various found
artifacts with the container?

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


Re: Building a uber/fat jar

2017-10-01 Thread Brian Toal
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 
wrote:

> I use Maven for the actual build. I use these dependencies (with
> 9.0.0.M26):
>
> 
> org.apache.tomcat.embed
> tomcat-embed-core
> 
> 
> org.apache.tomcat.embed
> tomcat-embed-el
> 
> 
> org.apache.tomcat
> tomcat-juli
> 
> 
> org.apache.tomcat.embed
> tomcat-embed-websocket
> 
>
> And use the Capsule Maven Plugin to build the actual runtime (better
> isolation than a shaded JAR):
>
> 
> com.github.chrisdchristo
> capsule-maven-plugin
> ${capsule.maven.plugin.version}
> 
> 
> 
> build
> 
> 
> your.main.class.here
> fat
> 
> 
> 
> 
>
> 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  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.
> >
>


Re: Problem with ClassNotFoundException: org.apache.tomcat.util.buf.UriUtil

2017-10-01 Thread Mark Thomas
On 01/10/17 20:30, Nicholas Cottrell wrote:



> /Users/nic/git/sprawk/etc/build.xml:493: java.lang.NoClassDefFoundError: 
> org/apache/tomcat/util/buf/UriUtil



> I've confirmed that the jars downloaded by maven do not include this class. 
> Should it be there? If not, how do I get it? I see the .java file in sources 
> in this version of Tomcat so maybe it's skipped in the packaging for some 
> reason?

You want tomcat-coyote.jar for that class.

Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Problem with ClassNotFoundException: org.apache.tomcat.util.buf.UriUtil

2017-10-01 Thread Nicholas Cottrell
Hi!

I have the following in my pom.xml


...
  7.0.78




  org.apache.tomcat
  tomcat-catalina
  ${tomcat.version}


  org.apache.tomcat
  tomcat-jasper
  ${tomcat.version}



  org.apache.tomcat
  tomcat-util
  ${tomcat.version}

And my Ant build.xml has:


  


However I can't compile my JSPs, since I get:

/Users/nic/git/sprawk/etc/build.xml:493: java.lang.NoClassDefFoundError: 
org/apache/tomcat/util/buf/UriUtil
at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at 
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.Main.start(Main.java:198)
at org.apache.tools.ant.Main.main(Main.java:286)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
Caused by: java.lang.NoClassDefFoundError: org/apache/tomcat/util/buf/UriUtil
at 
org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:258)
at 
org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:178)
at 
org.apache.jasper.compiler.TldLocationsCache.init(TldLocationsCache.java:247)
at 
org.apache.jasper.compiler.TldLocationsCache.getLocation(TldLocationsCache.java:208)
at 
org.apache.jasper.JspCompilationContext.getTldLocation(JspCompilationContext.java:623)
at 
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:484)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1421)
at org.apache.jasper.compiler.Parser.parse(Parser.java:138)
at 
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
at 
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
at org.apache.jasper.JspC.processFile(JspC.java:1260)
at org.apache.jasper.JspC.execute(JspC.java:1411)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
... 16 more
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.buf.UriUtil
at 
org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1374)
at 
org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1323)
at 
org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1076)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 36 more

I've confirmed that the jars downloaded by maven do not include this class. 
Should it be there? If not, how do I get it? I see the .java file in sources in 
this version of Tomcat so maybe it's skipped in the packaging for some reason?

My build.xml worked find with Tomcat 6.x but I just can't get it working now. 

Thanks in advance,
Nic.








[OT] JavaOne anyone?

2017-10-01 Thread Leon Rosenberg
Hi,

is anyone from the list at the java1?

regards
Leon