Re: Classpath issues with Embedded Tomcat 7

2012-04-20 Thread Pid *
On 19 Apr 2012, at 23:09, Konstantin Kolinko knst.koli...@gmail.com wrote:

 2012/4/20 Caldarale, Charles R chuck.caldar...@unisys.com:
 From: Adam Gordon [mailto:adam.n.gor...@gmail.com]
 Subject: Re: Classpath issues with Embedded Tomcat 7

 it's creating tomcat.9090 in the same directory as my
 web application.

 That looks like the pid file used for shutting down Tomcat via scripts.  I 
 don't think that has anything to do with what Tomcat uses for JSP 
 compilations.


 Citing from Tomcat.java:
 [[[
/**
 * Tomcat needs a directory for temp files. This should be the
 * first method called.

Maybe this should be a constructor argument, if it's a pre-requisite.


p





 *
 * By default, if this method is not called, we use:
 *  - system properties - catalina.base, catalina.home
 *  - $PWD/tomcat.$PORT
 * (/tmp doesn't seem a good choice for security).
 *
 * TODO: disable work dir if not needed ( no jsp, etc ).
 */
public void setBaseDir(String basedir) {
this.basedir = basedir;
}
 ]]]

 There is code somewhere in that class that implements what is written
 in the above javadoc.

 Best regards,
 Konstantin Kolinko

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


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



Re: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread icfantv
UPDATE:

Adding ALL my WEB-INF/lib jars to my launch command classpath causes the web
application to start, but I'm not sure this is correct.  If it is, what's
the point of the WEB-INF/lib directory?

Anyone have any thoughts here?

--
View this message in context: 
http://tomcat.10.n6.nabble.com/Classpath-issues-with-Embedded-Tomcat-7-tp4898646p4898810.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

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



Re: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Konstantin Kolinko
2012/4/19 icfantv adam.n.gor...@gmail.com:
 UPDATE:

 Adding ALL my WEB-INF/lib jars to my launch command classpath causes the web
 application to start, but I'm not sure this is correct.  If it is, what's
 the point of the WEB-INF/lib directory?

 Anyone have any thoughts here?


Subscribe to the Mailing list properly. Do not use Nabble.

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



Re: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Adam,

On 4/19/12 1:46 PM, Adam Gordon wrote:
 UPDATE:

If this is an update, why not reply to your original thread? It's
difficult to keep everything in context when you start a new thread.

 By adding all my jars in WEB-INF/lib to my launch command
 classpath, I can get the embedded server to run, but this does not
 seem correct as then what would be the point of WEB-INF/lib?

Your instincts are correct: you shouldn't have to add
WEB-INF/lib/*.jar to your CLASSPATH. Something else must be incorrect
with your environment.

 I've been unable to find any decent documentation on how to use
 Embedded Tomcat so I've been winging it.


The Tomcat source (specifically the test cases) is rife with examples
of use of Tomcat embedded: any test case that needs a running instance
uses the Tomcat class. Look through the build script (specifically,
how tests are run) to see what libraries are added to the bootstrap
CLASSPATH when launching them.

 The issue I'm having is that from what I've gleaned from the web
 all I *should* need in my classpath for my main method is my main
 class, tomcat-embed-core.jar, tomcat-embed-logging.juli.jar,
 tomcat-embed-jasper.jar, and ecj.jar but I'm finding that when
 trying to launch my main from the command line I keep having to
 append more and more jars from WEB-INF/lib to my classpath to get 
 it to continue to try and start up because it keeps spitting out 
 NoClassDefFoundErrors.

Can you give a specific example?

I was under the impression that it would use
 WEB-INF/lib for the web app's  classpath but this is not what's
 happening. The syntax used below was used from 
 http://people.apache.org/~markt/presentations/2010-11-04-Embedding-Tomcat.pdf,

 
see the section for running a web application.
 
 Here's my main:
 
 public static void main(String[] args) throws LifecycleException,
 InterruptedException, ServletException {
 
 Tomcat tomcat = new Tomcat(); tomcat.setPort(9090);
 
 File docBase = new File(/usr/local/foo/foo-ui); 
 tomcat.addWebapp(null, , docBase.getAbsolutePath());
 
 tomcat.start(); tomcat.getServer().await(); }
 
 and here's my launch command:
 
 user@host: /usr/local/foo/foo-ui $ java -cp 
 WEB-INF/classes:WEB-INF/lib/tomcat-embed-core-7.0.27.jar:WEB-INF/lib/tomcat-juli-7.0.27.jar:WEB-INF/lib/tomcat-embed-jasper-7.0.27.jar:WEB-INF/lib/ecj-3.7.1.jar

 
com.foo.WebAppMain
 
 Anyone have any ideas what I'm doing wrong?  Thanks.

Well, first, there's no reason to have all the Tomcat JAR files in the
webapp's WEB-INF/lib directory. Put them somewhere else. You might be
getting NCDFE because (for example) Tomcat.class != Tomcat.class when
the two are loaded by two different ClassLoaders. Take everything out
of your webapp's WEB-INF/lib directory that it doesn't use directly or
indirectly (i.e. all the Tomcat-specific stuff).

So, let's see what the javadoc for Tomcat.java has to say:

 * Requirements: * * - all tomcat classes and possibly servlets are
 in the classpath. * ( for example all is in one big jar, or in
 eclipse CP, or in any other * combination )

Once you've moved the Tomcat .jar files, this should be true.

 * - we need one temporary directory for work files

I don't see that you've set that up: you need to call Tomcat.setBaseDir().

 * - no config file is required. This class provides methods to *
 use if you have a webapp with a web.xml file, but it is * optional
 - you can use your own servlets.

Do you have your own web.xml file? Probably. If you follow the code of
the method you are calling (not sure why you are calling the
undocumented method instead of the documented one), you'll see that
ultimately, your webapp should be deployed with no default web.xml
(the server-wide one) and the ability to load your webapp's
WEB-INF/web.xml file.

 * There are a variety of 'add' methods to configure servlets and
 webapps. These * methods, by default, create a simple in-memory
 security realm and apply it. * If you need more complex security
 processing, you can define a subclass of * this class. * * This
 class provides a set of convenience methods for configuring webapp 
 * contexts, all overloads of the method codeaddWebapp/code.
 These methods * create a webapp context, configure it, and then add
 it to a {@link Host}. * They do not use a global default web.xml;
 rather, they add a lifecycle * listener that adds the standard
 DefaultServlet, JSP processing, and welcome * files.

What happens if you move the Tomcat classes outside of your webapp's
WEB-INF directory, adjust your CLASSPATH accordingly, and re-launch?
Be specific.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+QV/0ACgkQ9CaO5/Lv0PAx9QCfegBFQDChZN042ujT8X/DJ71z
8MgAn29JSoF3CtJ+SiQgc6nvDXEbxNVp
=GGaT
-END PGP SIGNATURE-


Re: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Adam Gordon
Chris-

 If this is an update, why not reply to your original thread? It's
 difficult to keep everything in context when you start a new thread.

I got in trouble for using Nabble and my original message never
posted, just the update.  Since I wasn't sure how to handle or correct
it all I just created a new thread knowing I'd probably get in trouble
again.  C'est la vie.

---

As far as the issues I was having.  I had WEB-INF/classes in my
classpath so that it could find my main class and WEB-INF/classes also
contained all my servlets, Spring services, GWT code, etc... hence the
third-party library dependencies for SLF4J, GWT, Spring, etc...

To solve, I moved the four required JARs (the three tomcat ones and
the ECJ JAR) to a separate directory and also created the directory
structure for the package in which my main class lives (e.g.
com/foo/bar/MainClass) and then just ran:

java -cp 
lib:lib/tomcat-embed-core-7.0.27.jar:lib/tomcat-juli-7.0.27.jar:lib/tomcat-embed-jasper-7.0.27.jar:lib/ecj-3.7.1.jar
com.foo.bar.MainClass

and everything worked correctly.

As an FYI, the docs say Tomcat provides a sensible default for a temp
dir which is why I didn't set one.

Thanks,

--adam

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



RE: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Caldarale, Charles R
 From: Adam Gordon [mailto:adam.n.gor...@gmail.com] 
 Subject: Re: Classpath issues with Embedded Tomcat 7

 the docs say Tomcat provides a sensible default for a temp
 dir which is why I didn't set one.

That's true when Tomcat is run as a normal server, but for embedded, it will 
use whatever the JVM decides to set for the system property java.io.tmpdir, 
which varies depending on platform.  Likely better if you pick an explicit 
location.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


Re: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Adam Gordon
On Thu, Apr 19, 2012 at 15:11, Caldarale, Charles R
chuck.caldar...@unisys.com wrote:

 the docs say Tomcat provides a sensible default for a temp
 dir which is why I didn't set one.

 That's true when Tomcat is run as a normal server, but for embedded, it will 
 use whatever the JVM decides to set for the system property java.io.tmpdir, 
 which varies depending on platform.  Likely better if you pick an explicit 
 location.

are you sure?  it's creating tomcat.9090 in the same directory as my
web application.

that aside, i do agree that it's FAR better to explicitly specify one
rather than crossing one's fingers.

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



RE: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Caldarale, Charles R
 From: Adam Gordon [mailto:adam.n.gor...@gmail.com] 
 Subject: Re: Classpath issues with Embedded Tomcat 7

 it's creating tomcat.9090 in the same directory as my
 web application.

That looks like the pid file used for shutting down Tomcat via scripts.  I 
don't think that has anything to do with what Tomcat uses for JSP compilations.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.



Re: Classpath issues with Embedded Tomcat 7

2012-04-19 Thread Konstantin Kolinko
2012/4/20 Caldarale, Charles R chuck.caldar...@unisys.com:
 From: Adam Gordon [mailto:adam.n.gor...@gmail.com]
 Subject: Re: Classpath issues with Embedded Tomcat 7

 it's creating tomcat.9090 in the same directory as my
 web application.

 That looks like the pid file used for shutting down Tomcat via scripts.  I 
 don't think that has anything to do with what Tomcat uses for JSP 
 compilations.


Citing from Tomcat.java:
[[[
/**
 * Tomcat needs a directory for temp files. This should be the
 * first method called.
 *
 * By default, if this method is not called, we use:
 *  - system properties - catalina.base, catalina.home
 *  - $PWD/tomcat.$PORT
 * (/tmp doesn't seem a good choice for security).
 *
 * TODO: disable work dir if not needed ( no jsp, etc ).
 */
public void setBaseDir(String basedir) {
this.basedir = basedir;
}
]]]

There is code somewhere in that class that implements what is written
in the above javadoc.

Best regards,
Konstantin Kolinko

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