Modifying Java Paths when deploying WAR - java

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.

Related

Make IntelliJ 13 run web application from tomcat directory

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.

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.

Deploying to Glassfish via Eclipse

I have set up a project inside Eclipse which I can debug on a Glassfish (3.1) server using the Eclipse Glassfish plugin. So when I click 'Debug on server', it uploads fine and I am able to step through the code correctly etc.
The problem is that I don't know if the program is being compiled/build (to a new .war) each time I press debug. I have got an Ant script in the project (as I previously built the project via terminal) but I'm not sure if it is actually being used in Eclipse.
Is there any way to check if my ant script is being run?
Also, how does Glassfish know what resources to upload? Does it just look for any .war files in the project?
Not sure about this particular jar plugin but as far as I know here is how Eclipse handles web applications:
Eclipse automatically compiles all of the sources in the class path
Then it creates a configuration file which tells Application Server to look for webapp on your project folder and does some mapping based
on your project setup. This will not create a WAR file. Eclipse will
just map WEB-INF/classes to {projectDir}/bin, your classpath jars to
WEB-INF/lib and so on.
When launching the Application Server, eclipse will feed it the config file made above.
Actually answering your question: Eclipse will not use the Ant script you created, nor will it create a WAR of any kind. It will just use project configuration to properly map project folders to web application structure.
Again, this is how eclipse handles things by default, the plugin you're using might do something different. This is based on my experience and is not based on some kind of documentation.

How do I deploy an unpacked maven project to Tomcat?

Per the Tomcat 7 documentation...
A web application is defined as a hierarchy of directories and files
in a standard layout. Such a hierarchy can be accessed in its
"unpacked" form", where each directory and file exists in the
filesystem separately, or in a "packed" form known as a Web ARchive,
or WAR file. The former format is more useful during development,
while the latter is used when you distribute your application to be
installed. (http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html)
The project I'm working with is a maven project (and must stay that way). I would like to simply put the project in my Tomcat webapps folder and run it from source (without doing a maven deploy) while I'm debugging/developing it. For production, I will use maven to build a war file for deployment. Is it possible to run a maven project from source? (without compiling to a war file?)
As Muel commented, you have to compile the files first, once you have all your files compiled, you can put it in any folder inside web apps (even ROOT, but should be empty), the app will use the folder name as context path (Except for ROOT that deploys in "/")

Configure: JRebel + External JBoss + Eclipse + Ant based deployment

I am trying to configure JRebel
Dev environment description:
Eclipse Juno IDE
JBoss 6.0.1 - Running externally from eclipse (same machine, not remotely)
Debugging: Remote, all hotswapping functionalities off
Ant script that: compiles, deploys and lifts target WAR to the JBoss
I have not used JRebel before, the configuration guide seemed pretty easy, but i am having troubles with my particular case.
All source (incl. jsps and images) is being compiled in project's bin folder.
Ant script creates WAR which holds separately JSPs, style, property files and compiled application classes are put inside dedicated jar in /web-inf/lib/ together with libraries. The script lifts the generated WAR to the JBoss and runs the server.
Where should i put my rebel.xml (i suppose in my project's bin folder?!) and what should i write into it in order to get jrebel-hotswapped the code changes inside the jar inside the war that is deployed in JBoss server.
I provided JBoss run script with necessary jrebel VM arguments.
Many thanks in advance!
rebel.xml should end up in WEB-INF/classes of your application. If you have dependencies in WEB-INF/lib folder, then every archive should have its own dedicated rebel.xml configuration file.
See the doc
If you deploy using Eclipse WTP, then it is fine to put it into source folder. But if you are using Ant to build the WAR, then you have to make sure that your Ant script will detect rebel.xml and copy it to the correct location.
The paths in the rebel.xml should point to the folder where the compiled classes are, i.e. the location where your IDE compiles these classes to.

Categories

Resources