Update regarding my second question below...The first question is still valid as is and I am still interested in input.
On Mon, Nov 23, 2015 at 3:38 PM, Yuval Schwartz <yuval.schwa...@gmail.com> wrote: > Hello, > > 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=""> > <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). > > This works on my development environment. > > 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"/> > > (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). > > First question: > Is this the correct way to set up tomcat so that my application has no > context path? 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: "/") > > 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. > 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. 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. > > 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). > It turns out that these warning and exceptions were caused because of missing jar files in the JDK's jre/lib/ext folder. tomcat-dbcp.jar is not available in amazon's tomcat8 AMI (my terminology might be a bit off). Instead, one needs to transfer both the commons-dbcp.jar and commons-pool.jar from tomcat/lib into the JDK's jre/lib/ext folder In addition, since this is not the default factory in the Resource element that I declared (as was the case with tomcat-jdbc), you need to explicitly specify it: factory="org.apache.commons.dbcp.BasicDataSourceFactory" > > Any insight or suggestions would be greatly appreciated. > I'm new to a lot of this (extremely new to deploying to a server). > > Thank you > _ > > > > > > >