Ways of deploying in Payara Micro under a certain context root - deployment

I'm looking for ways to deploy an application in Payara Micro under a specific context root (ideally an empty context, so the application runs at root).
As far as I know there are two methods:
Use an .ear file and specify the context root in the application.xml file:
<context-root>/</context-root>
Start Payara Micro and deploy programmatically
PayaraMicroRuntime instance = PayaraMicro.bootstrap();
InputStream is = new FileInputStream("thewar.war")
instance.deploy("name", "contextroot", is);
Is there any other way I'm missing? Both versions above are not suitable for me in my current setup.

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.

Configure the path (localhost) of the war application to be the root (Java EE)

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

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.

Unity Configuration using multiple config files

Is there a way to configure a container in multiple configuration files?
For instance, I want to register types for a container in a web.config file located at the root and also register types for the same container (and others containers) in the web.config file of sub-folders.
And also register other types for others containers in a company.config file in path C:\Company\Framework\Configs.
When I try to do this I get a ConfigurationError stating that the entry for the container has already been added.
EDIT: any suggestions here
http://unity.codeplex.com/Thread/View.aspx?ThreadId=23230
any more suggestions for sample code ?
I have a similar question posted here: WCF + Unity nested web.config problem
I have a web application with a subdirectory 'Services' which contains WCF services.
This services folder also has a web.config file containing my WCF configuration. That doesn't seem to be a problem for WCF.
The same web.config also has unity configuration for use inside my services. But i'm unable to load this configuration using 'GetSection'
If I move my unity configuration to the root web.config, everythings works fine.

Is it possible to have a servlet forward to a jsp outside of its context root?

We currently have an appserver setup where EVERYTHING is off of one big context root, and we copy class files and restart app servers to deploy. Not ideal.
I'm trying to set up an ant script to do the build and deploy using wdeploy, and everything works, except I need my servlet to forward to jsps outside of the context root of my war file deploy. So I figure if I can put a symlink in my war file, it can point to somewhere outside of my context root space.
This is the goal I'm trying to achieve, perhaps the symlink isn't the best idea.
I just need a way to forward outside of my context root from a servlet.
I'm not sure a symlink will work and I agree it's not a good idea. Try creating a virtual directory pointing to where your jsps are located.
You can always to HttpServletResponse.sendRedirect to send the user anywhere, but if you want to use RequestDispatcher.forward or jsp:forward, it only works within the app's context root.
I don't think it's that bad to have all your code under one context root, assuming it's related to one application. Creating multiple WARs for different parts of the same application seems to increase your maintenance cost with little gain.
It is possible, to forward to resources outside of the context of your webapp, if the other webapp is running in the same servlet-container.
For details see: Servlets: forwarding to a resource in a different webapp