tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rocha <daniel.roch...@hotmail.com>
Subject RE: Webapp in the same thread context
Date Fri, 27 May 2016 08:53:41 GMT
Hi,
Thanks for replying.
I have the following structure:
The application that starts the servlets and initializes the static objects:/home/project/lib/app.jar
The tomcat temporary folder "this.embedded.setBaseDir(getPath());" is located under:/home/project/temp_tomcat/
The servlets are located under:/home/project/webapps/servletname/
In the "servletname" directory I have what the compiler (I am using Netbeans as the IDE) generates
under build/web directory. This means I have the WEB-INF, META-INF and the web pages inside
the directory. The .class are inside the WEB-INF.
Under the WEB-INF/lib of the servlets directory I have the "app.jar" in each of them.
So, I tried to do something and it worked.
I put the "app.jar" inside the tomcat temporary folder "/home/project/temp_tomcat/lib" (as
a shared library) and I deleted the "app.jar" from each servlet (WEB-INF/lib/app.jar) and
it worked.

Can you please explain to me what really happened to start working?Is there another way (some
tomcat option) to do this without having to put the "app.jar" inside the tomcat temporary
folder? 

Thank you in advance,Best regards,Daniel Rocha

> Subject: Re: Webapp in the same thread context
> To: users@tomcat.apache.org
> From: chris@christopherschultz.net
> Date: Wed, 25 May 2016 14:19:22 -0400
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> Daniel,
> 
> On 5/25/16 11:03 AM, Daniel Rocha wrote:
> > I have a java application that was running with "Embedded" class 
> > from Tomcat 6.0.Now I am trying to upgrade it to run with Tomcat 
> > 7.0.69.
> > 
> > The current java application is initializing some static objects 
> > and then starts the "Embedded" class with some Servlets.The 
> > Servlets that were initialized access to the static objects from 
> > the application that started them. This works fine with Tomcat 
> > 6.0.
> > 
> > Now, I am using the "Tomcat" class from Tomcat 7.0 to start the 
> > same Servlets.The servlets are initialized and I can access to 
> > their context path.
> > 
> > The problem is when I try to access from the Servlet to a static 
> > initialized object from the application that started them.The 
> > object is null here.
> 
> Where is the .class file located for the servlet? Where is the .class
> file located for the "static initialized object" reference? You need
> to be very specific about what's going on, here, because lack of
> precision can cause all kinds of missteps.
> 
> > I do not know if this is related to the context class loader.
> 
> It's almost certainly related to the ClassLoader... probably the
> WebappClassLoader.
> 
> > The code looks something like this:
> > 
> > // Port number int port = 8080; // Create an embedded
> > serverthis.embedded = new Tomcat(); 
> > this.embedded.setBaseDir(getPath()); this.embedded.setPort(port); 
> > // Set default virtual hostthis.host = this.embedded.getHost(); 
> > this.host.setAppBase(getPath() + "/webapps"); // Create the ROOT
> > contextthis.rootcontext = this.embedded.addWebapp(this.host, "",
> > getPath() + "/webapps/ROOT"); 
> > this.rootcontext.setReloadable(false); 
> > this.rootcontext.addWelcomeFile("index.jsp"); // Create servlet
> > context this.rootcontext = this.embedded.addWebapp(this.host,
> > "/context",
> "/home/path/to/app");
> > this.rootcontext.setReloadable(false);context.setPrivileged(true);
> > 
> > // Set connector propertiesConnector connector =
> > this.embedded.getConnector(); connector.setSecure(false); 
> > connector.setProperty("maxThreads", "10"); 
> > connector.setProperty("acceptCount", "20"); 
> > connector.setProperty("asyncTimeout", "30000"); 
> > connector.setProperty("connectionTimeout", "30000"); 
> > connector.setProperty("socket.soTimeout", "30000"); 
> > connector.setEnableLookups(false);
> > 
> > this.embedded.setConnector(connector); // Start the embedded
> > server this.embedded.start();
> 
> There is nothing in that code that is going to cause any problem like
> you describe. Tell us how the code that fails interacts with the code
> that is (likely) loaded from the wrong ClassLoader.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
> 
> iQIcBAEBCAAGBQJXReyqAAoJEBzwKT+lPKRYyREP/iFMdNtenVwqDSw3u7senlVs
> UUQ4QrdiHa1CYtl3DZMNnxq47EnK8oKbHEsR4ELN4K1fJ2MzDC+gCL33AhFF8b1+
> bNRczRdj9aq3SbHqWR7Cb06CRj3qZ6FKexlHaHVgAVBuo0o7+Vp1+P843qWjDLCt
> ZrWQ9gdsMI/9spKXn11QnP/q0yW3SiMoTOTTob5ByEKfhZMFupuhCBZnhqQC2fZh
> D0iivElIaJer4Q5OXDblo4lBfwFSJtT2Xlkqx4B2xMNVf1obrYai4tGlXNtXVlwI
> wgsLvmaRT9tOCf/6uSnuTNKlxX5P3FKQYbyecsYUCmHysJ+f6kGIxY3PdwuL4Arq
> 4OlyfsYX6wDtcHGEw+T9gtG+Z+QQw1RKLwtYv6sasEjQIusVNJGwZbsWgi+TYNS5
> C2Ini934fDWJwc9DljEjvr3cYQMEt5ysMKNMVAG0d4SLsL9ug1iBiuv/ZH4LcG0m
> +PWq6kGOmlpUHq/j7ySvKadg/YvXzr5OTagr7hCn88Z3WU0K+oJcKgE9QA9qDHGc
> 9a+ZyNFRbdfh4yW5zmCbK+0EYH6BZ9mjKU/tOVjjaiqEU/AJOb9itLVHXz6yek5e
> LlHXomL1w1tJGQ9zYiJx3/oBHC1px05n0hqfKKkfbRjsUI44Mjuyqo0SpymWxQi/
> XuI+yXCgM4Vi7h4mcGFc
> =jHSA
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message