Make IntelliJ 13 run web application from tomcat directory - java

I'm having issues with running my application through intellij. I would like intellij to not run my application from its own folder (C:\Users[name].IntelliJIdea13...) but instead place my war file or exploded war into my tomcat /webapps folder and run form there. What is happening is i'm having issues accessing resources as my servletcontext points to my tomcat instance by the exploded war is not there, its in Ideas folder structure.
Currently I set CATALINA_BASE in my launch options which allows me to pull the correct keystore to run but that is living outside of the war.
I have tried changing where my artifact outputs too but what ends up happening is I get weird webclassloader errors due to library collision.

Related

How does intellij map war to webapps during deployment to tomcat

I want to know how intellij maps an artifact created in the 'out' folder to the webapps of tomcat.
My project is deployed successfully and I am able to see it in the browser. But when I check the webapps folder of the tomcat, I am not able to see my app folder.
I wanted to know how is intellij deploying to tomcat without moving the files to the webapps folder.
I found this question that is similar to mine but the answer does not mention the process.
I read about the different ways that tomcat deploys but couldn't get how exactly intellij is doing it.

Web Deployment Assembly not used by Tomcat7

My understanding is when running tomcat inside of eclipse, during publishing... eclipse will copy files based on the settings in Web Deployment Assembly to tomcat directory. I added my app to Tomcat 7 thru Server --> "Add or Remove...", when I start tomcat, I don't see any files been copied to /usr/share/tomcat7/wtpwebapps/myapp folder. BTW, I have all the folder structure (folders) under tomcat directory, but missing all the files (like .class, .properties, .xml and ...). This is the error I am getting when start tomcat. BTW, the directory show in the pic is the directory under tomcat. I thought the publishing process copies files from eclipse to tomcat dir? It looks like it's trying to copy files from tomcat dir to somewhere else. What am I missing? My Server path and Deploy path are all correct.
It's a permission thing. Also I recommend install tomcat manually instead of running apt-get.
Either https://askubuntu.com/questions/17223/permissions-problem-when-copying-files-to-usr-share-tomcat6 or http://www.frattv.com/tomcat-can-t-start-from-ide-eclipse-luna-wtp-intellij-idea-in-ubuntu/ will work.

Where is my webapp deployed(From Eclipse to Tomcat 7)

I am trying to deploy my Web application(Dynamic web Project) from Eclipse to Tomcat 7( in Windows). Although the deployment works, I would like to see where exactly(the location) the web app is deployed. I did search for my webapp (named as 'Demo') in TOMCATINSTALLATION/webapps directory. But could not find my application('Demo') there.
Double-click on the Eclipse Tomcat server instance and have a look at the configuration. If you are using the option "Use workspace metadata" then the app is deployed in a path like
<workspace>/.metadata/.plugins/org.eclipse.wst.server.core/tmpX/wtpwebapps/<context>
Not sure about particular Eclipse case, but usually IDE deployment works by dynamically overriding CATALINA_BASE environment variable and setting it to your project output folder. CATALINA_BASE tells Tomcat to search for your wepapps, server settings, etc. in the specified folder.
So answer to your question is that the actual working code sits somewhere in your project's build folder: subfolder build for regular projects or target for maven ones.

Modifying Java Paths when deploying WAR

I have a webserver that I developed in Eclipse with a local TomCat server. When developing, I often had to run scripts from the command line from my Java code. I just looked at the working directory that Java inside eclipse was working from (was in the Eclipse subdirectory somewhere) and put a ton of files and scripts in here.
Now when creating a WAR those paths are wrong. I'm just not sure how to integrate this all into my project correctly. Should I copy everything into the Eclipse project directory and make the Java 'home' path here - how can I set this up so that the WAR would work when deployed on a webserver?
Should I copy everything into the Eclipse project directory and make the Java 'home' path here - how can I set this up so that the WAR would work when deployed on a webserver?
That is a bad idea:
Since you can't change the "current directory" in a Java program, the only way to do that would be to "cd" to the Eclipse project directory and start Tomcat from there. Yuck!!
And that's conceptually wrong:
Suppose you had two WAR files created in two distinct Eclipse projects. An application cannot have two different "current" directories. It makes no sense.
What if you want to deploy to a Tomcat on a system that doesn't have the Eclipse projector available to it ...
The correct way to solve this is to put all of the requisite files into the WAR file, and then access them from your webapp codebase using either webapp relative file paths ... or via the classpath.
Yes, it will entail changing the code of your webapp, but it is the right approach.

How to Deploy to Intellij IDEA Tomcat Folder?

I use Intellij IDEA 11.1.2 Ultimate Edition. I run Tomcat 6 from Intellij IDEA. Beside my .war application I have another folder that has static HTML files. When I run tomcat manually from command line I put that folder under Tomcat's webapp folder and it automatically deploys it and works. However I want to debug my application so I want to run Tomcat from Intellij IDEA. I think that Intellij IDEA deploys tomcat applications into .IntelliJIdea11\system\tomcat folder. Where I can put my folder that contains static files when I run Tomcat from Intellij IDEA?
(I request the main page of static HTML file folder within an iframe at one of my HTML pages of .war file )
Any ideas?
Tomcat Run configuration has an option to deploy other applications from the server (that already present in the original webapps folder), like your static files:
Another option would be to create a second module for the static content with another artifact and deploy both artifacts from IntelliJ IDEA.
I think that CrazyCoder's answer is a little bit better. But here is my solution.
Go to File -> Project Structure...
Select your Web facet
In section Web resource directories click to +
Web resource directory path is your static content
Relative path in deployment directory is where you want to find it in your application war
If you want to debug you have no need to run Tomcat from IDEA. You can use remote debugging feature.
Just set up Tomcat to accept debug(listen to particular port). And create debug configuration from IDEA to attach to this port.

Categories

Resources