Configure the path (localhost) of the war application to be the root (Java EE) - java-ee-6

I want to change the path when I run my war-application locally...
Right now, it is running on the default setting...
http://localhost:8080/myproject-war/
and I want it to be the root, something like:
http://myproject-war.local/
or
http://myproject:8080/
How can I do that???
Note: My app is a Java EE 6 Application with Glashfish using Netbeans 7.3

This post helped me out How do you deploy a WAR that's inside an EAR as the root (/) context in Glassfish?.
First, I added a Standard Deployment Descriptor (application.xml) to the Enterprise Application Project.
Then, change the path of the context root of your web application: <context-root>/myproject-war</context-root> to <context-root>/</context-root> or <context-root />
Finally, (optional) remove or rename the Glashfish index page (or redirect it to the welcome page). located in the Glashfish default folder such as C:\Program Files\glassfish-3.1.2.2\glassfish\domains\domain1\docroot
Now the page web application will be visible on: http://localhost:8080/

Maybe you are mixing up stuff here - one thing you can and should do is setting the context root of your application. This is done in the server's deployment descriptor - in your case in glassfish-web.xml:
<context-root>/myproject</context-root>
(See The Java EE 6 Tutorial for more details.)
What you're asking in your example URLs is changing the host name, which is not related to your application or application server, but to your machine and OS settings.
You may put something in the OS hosts file (/etc/hosts on Linux, C:\Windows\System32\drivers\etc on Windows), but I don't see the point to do this. Your application runs on some host (may it be localhostor some external server) and this is how your URL starts.

you can put entry in host file. which is located in "C:\WINDOWS\system32\drivers\etc".
127.0.0.1 your_project_name

Related

IBM Liberty issue

An architect is having issues bringing Liberty up. Currently, an individual is running a server on his local computer and they want to move it to a shared server. When he tries to deploy a simple “helloworld” it’s failing and he is receiving an error “Context Root Not Found”. He is not sure what to set in server.xml file to have wlp recognize the application. They have ODM 8.5 on the mainframe. He thinks it might help if he saw an example of an EAR or WAR file deployed. Any ideas or suggestions?
Either put your application in the dropins folder, it will be detected and started automatically, or put it in the apps folder and configure in server.xml like this:
<webApplication id="HelloApp" location="HelloApp.war" name="HelloApp"/>
by default context root is application file name without extension, but you can change it by adding contextRoot="mycontext" attribute.

Generate code from deployed files

I had mistakely deleted my web services code. I don't have any backup of this code. Tried some file recovery tools but it didn't work. I have deployed the project in glass fish 4.0 server and the application works fine from there. So I am thinking is there any way I can generate the codes of that webservice?
Thank you
If you have the application deployed in your glassfish server then it is possible. You can always find your the .class files of original codes (not the one compiled by SEI) inside your domain folder of glassfish. Then you can use some third party tools to generate java codes from the class files. There are to ways that you can deploy your application in the glass fish server:-
By using the glass fish server web GUI and deploy it.
By using exernal IDE like eclipse where you create the glassfish server and deploy it.
For condition 1, goto :-
glassfish\domains\domain1\applications\__internal
where domain1 is your domain name. By default it is the name of your domain
For condition2, goto:-
glassfish4\glassfish\domains\domain1\eclipseApps
where domain1 is your domain name. By default it is the name of your domain
You can find your java codes inside WEB-INF\classes inside your project name.
Hope this helps.

Tomcat 6 Eclipse root deployment

I have a Java web application running on Tomcat6 built with Eclipse. It has always been run in a subdirectory:
/webapps/appDIR
As a result, the URL is:
www.application.com/appDIR
I now want it to just be deployed to the top level. I rename the directory to ROOT and extract the WAR. Set the permissions, and it doesn't work. It goes to an infinite redirect of the error page, and then the page dies.
I can rename the the directory to anything else and it works. For example I could call it test, in which case the URL becomes:
www.application.com/test
.....works fine. I just can't use "ROOT", which would allow the wwww.application.com URL to work.
I did some searching, and decided it was related to the context.xml file. It is currently sitting in the /WEB-INF directory (wrong?), and it only contains an end tag of "" (more wrong?). I moved that file to the /META-INF directory, and it didn't work. I figured that maybe it couldn't be empty and I added the contents of the following link to it:
http://www.wellho.net/resources/ex.php4?item=a654/6_context.xml
And still no go.
Any ideas? For a little more background, I'm now deploying it to Amazon's Beanstalk whereas before it was self hosted. Beanstalk defaults to deploying to ROOT, and I didn't see a reason to fight them on it, whereas Eclipse feels differently.
You mentioned: "Beanstalk defaults to deploying to ROOT, and I didn't see a reason to fight them on it".
If you care to fight -
A hack to be sure, but to get our app to deploy under a subdirectory, we did the following with a beanstalk config file (.ebextensions)
commands:
# This modified the default beanstalk deploy script so that our WAR file sits in appropriate subdirectory.
fixdeployscript:
command: sed -i 's/webapps\/ROOT/webapps\/MyAppName/g' /opt/elasticbeanstalk/hooks/appdeploy/enact/03deploy.sh

crossdomain.xml location when Tomcat is running in Eclipse

I need to use a crossdomain.xml file to access my WebApp from a dev sandbox.
I gather from other SO posts that it should be accessible at http://localhost:8080/crossdomain.xml , hence in tomcat ROOT webapp.
Where the heck is that ROOT directory when running Tomcat in Eclipse?
Edit: Tomcat is using a Runtime Environment named "Apache Tomcat v6.0" which is using a "Tomcat installation directory" set to "D:\dev\apache-tomcat-6.0.33"
I tried to drop crossdomain.xml in "D:\dev\apache-tomcat-6.0.33\webapps\ROOT" but I still get a 404 trying to access http://localhost:8080/crossdomain.xml from a browser. In fact, anything in that ROOT directory is accessible.
Edit 2: In the server launch configuration, there is an "Arguments" tab listing the following -Dcatalina.base="D:\dev\workspaces\project\.metadata\.plugins\org.eclipse.wst.server.core\tmp1" -Dcatalina.home="D:\dev\apache-tomcat-6.0.33" -Dwtp.deploy="D:\dev\workspaces\project\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps" -Djava.endorsed.dirs="D:\dev\apache-tomcat-6.0.33\endorsed"
Hence, I pasted the crossdomain.xml into D:\dev\workspaces\project\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\ROOT and ... it worked. Seriously.
Thanks in advance
As per edit #2
In server launch configuration, there is an "Arguments" tab listing the following VM Arguments
-Dcatalina.base="D:\dev\workspaces\project\.metadata\.plugins\org.eclipse.wst.server.core\tmp1" -Dcatalina.home="D:\dev\apache-tomcat-6.0.33" -Dwtp.deploy="D:\dev\workspaces\project\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps" -Djava.endorsed.dirs="D:\dev\apache-tomcat-6.0.33\endorsed"
Hence, I pasted the crossdomain.xml into D:\dev\workspaces\project\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\ROOT

Is there a way to get the absolute path of the context root in tomcat?

I have a problem that, after a lot of reading and research, seems like tomcat is running another instance of itself and thus serving an old version of my updated app (or somehow has cached an older version of my webapp somewhere only serves that.)
I work on the app in eclipse on a windows machine and deploy it on a Linux server as a ROOT app (Renaming the war file to a ROOT.war).
What I'd like to know is if there's a way to locate the older version that tomcat is serving by getting tomcat to log an output of the context root of the servlet that's serving the older version of the app.
As it stands it the moment any files created by the updated app get created in the right directory but because the app instances are different it can't access the files shortly after they're created.
Any help/hints would be welcomed
To answer the question in the title, let your code basically do the following:
System.out.println(getServletContext().getRealPath("/"));
To solve the problem described in the question, shutdown Tomcat and delete everything in its /work directory, delete the expanded WAR in /webapps and remove the /Catalina subdirectory of /conf directory (if any) and then restart.