I'm working in a Maven web application (Java), Glassfish as web server. I have a directory for example path = Application_name/src/main/webapp. But I need to access the directory as http:///localhost:8080/webapp. Do I need some configuration for this in my application or in Glassfish or some other configurations?
You configure the port in glassfish directly. 8080 is the default port. See here if you want to change: https://blogs.oracle.com/openroad/entry/changing_default_glassfish_port_numbers.
For the name (webapp), it happens in your web.xml. Add this:
> <context-param>
> <param-name>webAppRootKey</param-name>
> <param-value>webapp</param-value>
> </context-param>
I suspect you are using Maven, resources in the /src/main/ressources/ folder should be copied as such in the root of your web application.
It sounds like you are talking about how to deploy the application:
Make a web.xml and glassfish-web.xml
Put them in webapp/WEB-INF
Have maven build a war file using the war plugin
Deploy war to glassfish via maven, the command line (asadmin), or with the admin console web page (typically http://yourmachine:4848)
http://maven.apache.org/plugins/maven-war-plugin/usage.html
look up "context-root" in glassfish-web.xml (or older versions sun-web.xml) for example: http://docs.oracle.com/cd/E19798-01/821-1750/beasg/index.html
For faster development you can also deploy an "exploded" war file or use the auto-deploy directory. http://docs.oracle.com/cd/E18930_01/html/821-2417/gilfm.html#SJSASEEADGfvxze
Related
I am using the simple IntelliJ web project with the default configuration.
I don't see any servlet mapping in the web.xml file:
web.xml file
However, when I run the project in IntelliJ it just works fine:
Project
But when I build it as a war file and deploy it with my tomcat server I can't access the hello-servlet.
Why Local IntelliJ tomcat server works even without proper servlet-mapping on the web.xml file and why it does not work on the tomcat server when I copy the war file into webapps directory.
I am trying to deploy my web app as a WAR file to WildFly 9.
I can specify the context path of the web app by renaming the WAR file in the deployments directory or by specifying the context in WEB-INF/jboss-web.xml inside the WAR file.
Is there a way to specify the context path outside the WEB-INF directory of the WAR file? This way it would be possible to change the context path after packaging the WAR.
You can specify the context path at deployment time by using the CLI to perform the deployment.
[steve#mylaptop wildfly-9.0.0.Final]$ bin/jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone#localhost:9990 /] deploy /path/to/my-app-1.0-SNAPSHOT.war --runtime-name=foo.war
This will result in your application being available at /foo
Use
deploy --help
for more information.
You can also do this via WildFly Maven Plugin as part of your CI job or similar.
We are using following command to deploy the war file to another context root:
org.wildfly.plugins:wildfly-maven-plugin:deploy-only
-Dwildfly.deployment.filename=app.war
-Dwildfly.deployment.runtime.name=appcontext.war
The app will be deployed under /appcontext.
Note, you should remove the context-root from your jboss-web.xml otherwise this value will win always.
There is the possibility to change context root of war application in runtime using CLI console Command Line Interface in Wildfly. It's possible with command deployment-overlay, in this way:
deployment-overlay add --name=myAppOverlay \
--content=/WEB-INF/jboss-web.xml=/myFiles/new-jboss-web.xml \
--deployments=myApp.war --redeploy-affected
This command forces Wildfly to load the content of file new-jboss-web.xml into the internal Wildfly cache and use it (during every deployment of myApp.war) as the replacement of /WEB-INF/jboss-web.xml file of your war web-archive. As you already know, context of web application could be therefore defined in new-jboss-web.xml in following way:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>myNewPathToApp</context-root>
</jboss-web>
Besides add action, deployment-overlay CLI command has also other actions in order to manipulate with deployment overlays (e.g. remove overlay, etc.).
The context root for a web application is determined in three different ways:
If it's deployed as part of an EAR, the context root is specified in the application.xml file of the EAR.
If it's deployed as a standalone WAR, the context root can be specified in the WEB-INF/jboss-web.xml.
If no context root is specified, the context root will be the name of the WAR file.
I don't know a fourth option.
See also the official documentation: https://docs.jboss.org/jbossas/guides/webguide/r2/en/html/ch06.html
I have a Java web project in Eclipse which I run through Eclipse on Apache Tomcat.
Is there a way for me to permanently deploy the project on Tomcat such that it runs without having to open Eclipse and rather just starting Tomcat?
If yes, then what steps do I need to follow?
*UPDATE*
If I take the .war file and deploy it on another system will it work? Note that I am using a MySql database in this project. So will transferring the .war file also transfer the database?
You package the project into a war file (since it is a web project) and put that one into the Tomcat's webapps folder. The deployment should then happen automatically, when Tomcat is started.
Generate a WAR file within Eclipse. (Properties->Export->WAR File)
Place this file in the {installation}/webapps folder of Tomcat.
It should deploy now.
I have a Java Web project (Struts + Spring) working perfectly in my localhost. I have to deploy it on my website, but the Tomcat Manager interface given by the webhost says it cannot upload a WAR file due to safety reasons. When contacting the tech support I was told it is not possible to upload a WAR and that I should try deploying my project by uploading the files directly (I have FTP access).
My problem is that no one at the tech support gave specific instructions on where I should put my project files (I don't know if it should be on de same folder the WAR would be sent to) neither how to start/stop it (Will the Tomcat Manager recognize it once I upload the files?).
You can always try to upload a war file to webapps folder of tomcat.
if tomcat is running with autoDeploy set to true it will auto deploy your application.
i think that the same will happen if you upload the exploded war to the webapps, the context will be the name of the directory you put your files in.
Just place your apllication's root folder to the Tomcat's directory webapps and configure tomcat to auto deploy. Restart the server and your application will be deployed.
You transfer the files to the same place as the war file would go - but just as an expanded war.
Whether or not tomcat will recognise that the files have changed depends on the configuration of the tomcat server. I'd just give it a go - transfer the files and see what happens. If it doesn't pick up the changes then you'll need to find out from tech support how to restart tomcat.
I've made a very small web app with eclipse, including
HomeServlet.java
home.jsp
web.xml
just echo'ing Hello world!. I've made my own build.xml file, and it's building succesfull.
So now I've got my build folder, where HomeServer.class is located, and my web folder, where home.jsp is located.
I've downloaded Tomcat 7 (and got it working at localhost:8080), how can I configure my server.xml in a way that I can view my app at something like: localhost/app/home ? I'm running Windows
You don't need to configure anything in Tomcat. You should just create a directory structure like the following, and drop this directory in the webapps folder of Tomcat:
myWebApp
WEB-INF
classes
com
mypackage
HelloServlet.class
web.xml (optional if the servlet uses annotations)
home.jsp
This is the structure of a standard Java EE webapp. It's described in every tutorial about Java EE webapps, and in Tomcat's documentation.
Note that it's a good idea to rely on Ant, Gradle or Maven to build your app, but that Eclipse (in its enterprise edition) supports Java EE webapps, and can create this structure for you and deploy the app directly from the IDE.