I currently have an apache tomcat application running on my machine. I need to make this application accessible over an external URL.
I can access the application locally at http://localhost/c. I want to be able to access the application externally at https://example.com/b/001/c. TO achieve this, I made the below change to my conf/server.xml file
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="" path="/b/001" reloadable="true" />
After making this change, my local set up works fine when I test with the below URL
http://localhost/c/1.jsp (works fine)
When I try to load the external URL (https://example.com/b/001/c/1.jsp) however, I get the below error
An error occurred at line: [15] in the generated java file: [......./1_jsp.java]
Only a type can be imported. a.c.d.e.database.DB resolves to a package
What change should I make to make this publicly available on the external server?
Related
I do have a Spring Boot Application which uses custom context.xml for the tomcat.
The context.xml contains property, defining the spring active profile
<Context>
<Environment name="spring.profiles.active" value="profileName" type="java.lang.String" override="false" />
</Context>
File location is the /src/main/webapps/META-INF
I was expecting that after the file is deployed to the tomcat, context xml will be automatically picked by tomcat and thrown to the conf/catalina/localhost/
As it turned out, the war was deployed, but the conf/catalina/localhost stayed empty.
After reading the docs i've found out that the server.xml has to be updated with the copyXML parameter as Host container.
The documentation says:
copyXML
Set to true if you want a context XML descriptor embedded inside the application (located at /META-INF/context.xml) to be copied to xmlBase when the application is deployed. On subsequent starts, the copied context XML descriptor will be used in preference to any context XML descriptor embedded inside the application even if the descriptor embedded inside the application is more recent. The flag's value defaults to false. Note if deployXML is false, this attribute will have no effect.
My Host looks like
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" copyXML="true">
</Host>
After restarting the server and redeploying the app, the /conf/Catalina/localhost still stayed empty.
Do you have any suggestions, what actions have to be taken in order to use custom context.xml?
I've figured it out.
My build script did not copy the file correctly, the file name was not "context.xml" but "appName.xml" and tomcat didn't pick it up.
/...too long and unclear explanation.../
In other way, I search the correct way to reach the site with just (one or more) domain name (then www.my_domain.it and not www.my_domain.it/appname), and all of these must point to the same instance of the webapp (so that from any domain name you access, the same Runtime data will always be displayed).
So, yes I have deployed the WAR file in tomcat/webapps folder, now, the correct to edit the conf/server.xml to get the result mentioned above, corresponds to one of the following?
1.
<Host name="my_domain.eu" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<Context path="" docBase="appname" debug="0" privileged="true" />
...
</Host>
2.
<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<Context path="" docBase="appname" debug="0" privileged="true" />
...
</Host>
3.
<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<Context path="/appname" docBase="appname" debug="0" privileged="true" />
...
</Host>
4.
<Host name="my_domain.eu" appBase="webapps/appname" unpackWARs="true" autoDeploy="true">
<Alias>www.my_domain.eu</Alias>
<Alias>www.my_domain.it</Alias>
<Alias>www.my_domain_2.it</Alias>
<!-- without context definition -->
...
</Host>
Otherwise, what is the correct solution?
Thanks to all!
I'm assuming that you have one of the instances of your app in the webapps directory, from where it's automatically deployed under its name. With the Context element, you can deploy applications from anywhere in the filesystem.
However, it's best practice to not edit server.xml with this information, but rather create individual context.xml files in conf/hostname, or just deploy to the host's webapps directory. Anything that you're configuring in server.xml requires a server restart if you want to change anything. Configuration outside of server.xml can be picked up at runtime, without restart.
Edit: Probably the takeaway of my previous answer wasn't clear:
When you use Context elements to configure: I'm proposing not to use the webapps directory for deploying your webapps. Just point to the directory where you actually deployed your webapp. This will make sure that no context is deploying your app from webapps/appname as /appname, even though your context definition points to /.
An alternative is to deploy your application with the name ROOT in webapps - this is a shortcut to actually deploy this webapp as / (careful: ALL CAPS for the directory- or file-name (ROOT.war) even on Windows if I remember correctly). But IMHO it would be clearer if you decide for either Context definition to determine the path (but deploy outside of appbase (webapps), or deployment in appbase (e.g. webapps) deployment.
Mocking around with appbase to point to some directory within webapps will make sure that you irritate anyone who is expecting that applications in webapps directory will deploy to Tomcat. That's an easy way to sink a lot of time into debugging phantom problems - don't do that.
I use the virtual directory to serve the static resource uploaded by user. So I don't need to backup these files when redeploying the app.
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="/upload" docBase="/Users/junyu/Web/upload/"/>
</Host>
I wrote these code into server/server.xml,and could be detected by gretty buildProduct task。Here is the output directory:
directory
Running output:
output
The upload context start successfully, but I couldn't access the pics in the docBase. 404 error.
Abandon the method using server.xml to config context.
Just config in the output/hello-web/server.json as following:
"webApps": [
{ "contextPath": "/hello-web", "resourceBase": "webapps/hello-web.war" },
{ "contextPath": "/upload", "resourceBase": "/Users/junyu/Web/upload/" }
]
The upload context will work, and pics in docBase could be accessed.
The question is server.json be newly produced in every build, and I have to change the server.json again. Is there a way to config once for all.
And, 'Web-app extra resource bases' just copy the resources into the project, and won't change after the original resource files change.
I need help in redirecting URL for an application deployed in tomcat7.
When we use "www.portal.com/portal", am able to view the site.
I want to view the page by just entering the URL as "www.portal.com". So, i need help in what need to be modified in tomcat7 configuration to get this done.
You can name your application ROOT or change the path to your application in tomcat's server.xml file.
This is an example of a mapping in the server.xml file:
<Context docBase="portal" path="/portal" reloadable="true"
source="org.eclipse.jst.jee.server:portal" />
To load the portal application without using /portal you need to change it to:
<Context docBase="portal" path="" reloadable="true"
source="org.eclipse.jst.jee.server:portal" />
I am using tomcat 7.
When I set context different from war file name, everything works fine.
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context docBase="../webapps/abc.war" path="/def" reloadable="true" />
</Host>
But at tomcat startup I see two exploded folder abc and def.
Please help if anybody knows about this issue resolution.
Thanks.
From the Tomcat doc (see "path" attribute):
Even when statically defining a Context in server.xml, [the path] attribute
must not be set unless either the docBase is not located under the
Host's appBase or both deployOnStartup and autoDeploy are false. If
this rule is not followed, double deployment is likely to result.
This is a bit obscur, but my understanding is that you need to use an xml context file to achieve what you are trying to do. How to define a context config file is documented in the above link.
A simpler fix would be to just rename your war file to def.war.