Deploying Java application to Tomcat root directory in Digitalocean [duplicate] - java

This question already has answers here:
Deploying my application at the root in Tomcat
(10 answers)
Closed 8 years ago.
I tried to deploy my application file to Tomcat 7. I have successfully deployed them, but I can see my files only under http://example.com:8080/myproject/index. (Assume that my project folder is myproject and my domain is example.com.)
I would like to to access to my domain like this: http://example.com/index.
How can I do that?

ok
I have solved the problem.
in the default server.xml file tag like this,
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
but I have removed that and changed like these
<Host appBase="webapps" name="example.com" unPackWars="true" autoDeploy="true">
<Context path="" docBase="myproject" debug="0" reloadable="true"/>
</Host>
<Host appBase="webapps" name="www.example.com" unPackWars="true" autoDeploy="true">
<Context path="" docBase="myproject" debug="0" reloadable="true"/>
</Host>
and than I have changed
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
like this
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
now it works:)

Related

Stopping and starting a service present in server.xml using tomcat manager application/api (Single tomcat instance)

I have multiple services defined in server.xml and below is the one which i need to restart(stop and start again) using tomcat manager application/api.
<Service name="myService">
<Executor name="myExecutorPool" namePrefix="my-http-pool"
maxThreads="10" minSpareThreads="1"/>
<Connector
port="8701" protocol="org.apache.coyote.http11.Http11Nio2Protocol" SSLEnabled="true"
executor="myExecutorPool"
maxSavePostSize="-1"
scheme="https" secure="true"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100"
sslEnabledProtocols="${sslEnabledProtocolsMediumSecurity}" server=" "
allowUnsafeLegacyRenegotiation="false"
clientAuth="want"
bindOnInit="false"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"
keystoreType="PKCS11"
keyAlias="server"
trustManagerClassName="com.example.com.myproj.cert.RestTrustManager"
sendReasonPhrase="true"
sslImplementationName="com.example.com.myproj.cert.MyProjImplementation"
ciphers="${tls.ciphers}"
/>
<Engine name="myEngine" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.MethodsValve" methodsSupported="GET,POST,PUT,DELETE,HEAD" />
<Host name="localhost" appBase="mywebapp"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="../webapps/ROOT" >
<Valve className="org.apache.catalina.valves.RedirectValve" sendToApp="/myapp/" />
</Context>
</Host>
</Engine>
</Service>
When i do curl -username:password http://localhost:8080/manager/text/list , i don't see this above service listed. It means i assume that, this service is not running as a separate service but contained inside appserver.
So i won't be able to do something like http://localhost:8080/manager/text/reload?path=/myService.
Can you please help here, how do i stop/start (restart) this particular service using tomcat manager app?
If JMX can be used here, can you please provide any links/resources for the same mentioning how to do that?

Resource URIs not working in Java RESTful web service on tomcat 8 server

I created a RESTful web service using auto generated entity classes with netbeans. I also used maven. I deployed this in tomcat 8 as localhost. I do see the index page, but I cannot access any endpoints. I initially ran this locally on Glassfish server and it worked fine.
I tried test resource uri in netbeans but it says,
Unable to open resource URL : localhost:8080//api/activity
Here is my server.xml file from apache tomcat.
<?xml version="1.0" encoding="UTF-8"?>
--><Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context antiJARLocking="true" docBase="C:\xxx\yyyy\apache-tomcat-8.0.36\apache-tomcat-8.0.36\wtpwebapps\xxDBWithMaven" path="/VoyateDBWithMaven" reloadable="true" source="org.eclipse.jst.jee.server:VoyateDBWithMaven"/></Host>
</Engine>
</Service>
</Server>
Is there anyway I can fix this so the resources can be accessed? It's confusing because the application gets deployed and the index file is displayed.
Unable to open resource URL : localhost:8080//api/activity
You have two slashes between "localhost:8080" and "api/activity". Remove one in the configuration where you specify the path: api/activity instead of /api/activity.

How to start/stop an application from a webapplication running both on same tomcat

I need some help: I have two .war files running on tomcat 7, one is a webapplication, the other one is just a "normal" java application. Now I want to figure out how to start/stop the application from my webapplication. Both applications are on the same tomcat. Operation system is Ubuntu 14.04.
Thanks for your help
you can configure that in your server.xml file and put 2 services :
<Service name="app1">
<Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="app1"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
<Service name="app2">
<Connector port="8082" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="app2"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
Then the application will run on
app1 on http://localhost:8081
app2 on http://localhost:8082
Resource Link:
Listen Multiple Ports in Tomcat
How to run different apps on single Tomcat instance behind different ports?

Tomcat ssl port not redirected automatically

i enabled both non-ssl(8440) connector and ssl(8445) connector in server.xml, when ever i started the server it redirects me to "http://localhost:8445/" but i given this port in ssl connector.
When i am trying to access http://localhost:8440 , it allows me to enter application ( it must redirect to the ssl port as i given redirect port)
every thing working fine , if i removed non-ssl connector.
tomcat version : tomcat 5.0.28
-thanks in advance
My server.xml entries
<Connector port="8440" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8445" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
connectionTimeout="20000" debug="0" disableUploadTimeout="true"
emptySessionPath="true" enableLookups="false" maxThreads="150"
minSpareThreads="25" name="SSL" port="8445" scheme="https"
secure="true" sslProtocol="TLS"/>
server.xml file
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
<Connector acceptCount="100" connectionTimeout="20000" debug="3" disableUploadTimeout="true" enableLookups="false" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" name="WebServer" port="8440" redirectPort="8445"/>
<Engine debug="0" defaultHost="localhost" name="Catalina">
<Realm allRolesMode="strictAuthOnly" appName="myapp" className="com.authentication.CustomJAASRealm" roleClassNames="com.authentication.RolePrincipal" userClassNames="com.authentication.UserPrincipal">
</Realm>
<Host appBase="webapps" autoDeploy="false" debug="0" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
<Valve className="org.apache.catalina.authenticator.SingleSignOn" debug="0"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%u %U %S "%{Referer}i" %a %A %m %t %D %b %s "%{User-Agent}i"" prefix="access_log." resolveHosts="false" rotatable="false" suffix="txt"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/>
<Context debug="0" docBase="${home}/webapps" path=""/>
<Context appBase="webapps" debug="0" docBase="${home}/help/" path="/help" reloadable="true"/>
</Host>
</Engine>
Please always read the documentation that help you to learn. You can check it HERE.
Go to your $TOMCAT_HOME/conf/server.xml and change redirect port:
<Connector port="8080"
enableLookups="false"
redirectPort="8440" />
<Connector port="8440" protocol="HTTP/
enableLookups="false"
redirectPort="8445" />
Cheers!!

Tomcat 8 - static resources / assets can't get this working

C:\asset (there I have images like 1.jpg / 2.jpg / 3.jpg etc)
My tomcat server.xml looks like this:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/test" docBase="C:/asset" debug="0" reloadable="true" crossContext="false"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
Still when i go to localhost:8080/test/1.jpg I have 404 error any ideas why this don't work ?
Another question is there any possibility to configure this path in my spring project ? As a variable ?

Categories