Thanks a lot Christopher, my response is below.

On Tue, Nov 24, 2015 at 2:26 PM, Christopher Schultz <
ch...@christopherschultz.net> wrote:

> Yuval,
>
> On 11/23/15 8:38 AM, Yuval Schwartz wrote:
> > I am using tomcat 8.0.22.0
> > Language: Java
> > development: Windows, NetBeans.
> > deployment: ec2 linux
> >
> > I am still having trouble understanding/working with "path" and "docBase"
> > of context element.
> >
> > I have two questions:
> >
> > First of all, I have a context.xml file in the WEB-INF folder of my
> > application (call it "myApplication" henceforth) that looks like:
> >
> > <Context path="">
>
> You should never specify the "path" attribute in your context.xml file.
> Instead, name the WAR file (or exploded directory) the same name as you
> want your context's path to be. For a path of "" (empty), use the name
> ROOT.war (or ROOT directory).
>

Executed. However, when I work in my development/local environment (not
sure what the correct terminology is for this) I still specify path=""
(since, when deploying with netbeans, a file is not generated in the
tomcat/webapps directory). Is there a preferred way to do this on my local
environment?

When deployed on a Linux server, Is it ok to modify the context.xml file in
tomcat/webapps/myApplication/META-INF (I think tomcat automcatically
redeployed after I made a change)?


>
> > <Resource name="jdbc/some_db" auth="Container"
> >         maxActive="100" maxIdle="30" maxWait="10000"
> >         username="blah" password="blahblah"
> >         driverClassName="com.mysql.jdbc.Driver"
> >         url="jdbc:mysql://localhost:3306/some_db?autoReconnect=true"
> >         logAbandoned="true" removeAbandoned="true"
> >         removeAbandonedTimeout="60" type="javax.sql.DataSource" />
> > </Context>
> >
> > My context path is set to the empty string because once I set up a domain
> > name it will be redundant to have both the application name and domain
> name
> > in the url (they are the same).
>
> See above.
>
> > This works on my development environment.
>
> You may notice that your application is deployed on both context paths,
> taking up twice as much heap space. Or it might not. Using "path" within
> a context.xml file not well-defined, but it is expressly prohibited in
> the documentation[1] though not actively prohibited by code.
>
> > When I deploy this to a linux server of an ec2 instance (on aws) I add a
> > line to the server.xml file (in tomcat/conf) under the <Host> element
> which
> > reads:
> > <Context path="" docBase="myApplication"/>
>
> You should not do this. Instead, drop your ROOT.war into Tomcat's
> deployment directory. If you move to EBS, you'll just be deploying the

WAR file anyway and shouldn't touch the application servers at all.
>

Right, I did this and it worked. When you say "EBS" do you mean Amazon's
Elastic Beanstalk? or Amazon's Elastic Block Store?


>
> > (If I don't add this element to the server.xml file then entering just
> the
> > domain in the url takes me to the Apache Tomcat "successful installation"
> > page rather than to the welcome page of myApplication).
>
> Use ROOT.war.
>
> > First question:
> > Is this the correct way to set up tomcat so that my application has no
> > context path?
>
> No. Note that it /does/ have a context path: it's just an empty string.
>
> > Not sure if this leads to the "double deployment" problem or
> > not. When I open the tomcat manager I see two applications: one with
> path:
> > "/" and the other with path "/myApplication". (for some reason, I don't
> > have the option to "undeploy" the application with path: "/")
>
> You don't have that option because you have put your <Context> into
> server.xml.
>

Removed Context element from Server.xml.


>
> > Second question:
> > The resource element within the context element of my context.xml file
> > (located in WEB-INF) specifies a url that is specific to my development
> (ie
> > local) environment.
>
> Which URL? The JDBC URL?
>

The URL attribute of the Resource element, specified above as:
url="jdbc:mysql://localhost:3306/some_db?autoReconnect=true"

But I think you can disregard the sentence above. I'm not even sure that
once I'll deploy I'll want to connect to my development DB instead of my
deployed DB (ie: maybe I'll want to connect to the deployed DB in both
cases...)


>
> > When I deploy myApplication to the ec2 instance I would like the resource
> > element to have a different url attribute (since it will now be
> connecting
> > with a database on an aws server).
> > One way that I found to do this was to add to the context.xml file in the
> > tomcat/conf directory of my server.
>
> Nonnononoon. Never modify the conf/context.xml file... that changes the
> defaults for every application deployed. While you may be deploying only
> a single application, it then separates your configuration into two
> files when one single file will do.
>
> > There I add a resource element (between
> > the existing context element) which is identical to the one above only
> with
> > a url attribute that points to the database hosted on aws.
>
> Package your WAR file with the correct URL and then deploy it.
>

Executed.


>
> > This way, my application is able to connect with my database without me
> > changing any of the code in myApplication.
> > However, my Catalina.log file displays:
> > WARNING [localhost-startStop-1]
> > org.apache.catalina.core.NamingContextListener.add Resource Failed to
> > register in JMX: javax.naming.NamingException: Could not create resource
> > factory instance [Root exception is java.lang.ClassNotFoundException:
> > org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory]
> >
> > And my localhost.log file shows a nullpointerexception for the line in my
> > code:
> > ic.lookup("java:comp/env/jdbc/some_db");
> > (Where ic is an InitialContext Object)
> >
> > There are also problems in the deployed website with some of the code
> that
> > grabs data from the db (but some of the db related code works
> successfully).
> >
> > Any insight or suggestions would be greatly appreciated.
> > I'm new to a lot of this (extremely new to deploying to a server).
>
> This second issue is discussed in another part of this thread.


Thanks.


> -chris
>
> [1]
>
> http://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Defining_a_context
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to