Eclipse, Tomcat project context root is eclipse folder
Asked Answered
L

1

8

I'm having a little problem configuring my Tomcat Project. In short, I'm working on a Dynamic Web Page project but there seems to be some confusion as to from where I am running the application.

Running the following code

File f = new File("");
System.err.println(f.getAbsolutePath());

yields the output C:/Eclipse which happens to be where I run Eclipse. Normally I'd expect this to be the output catalog, but it is not the case this time.

My eclipse project is configured to have myProject/WebContent/WEB-INF/classes as output folder

How can I configure to the desired directory? Right now I need to use absolute paths which won't work for all members of the project.

Lichtenfeld answered 10/4, 2012 at 12:17 Comment(8)
So what is the question here? Your current directory is where your application is started from by Eclipse. Your output folder - is part of the classpath for your app.Spigot
Updated question. I want the directory to be a specific subfolder of my project in the workspace but my configuration seems to have no effect.Lichtenfeld
I'm sorry, I'm still not following you. What is the purpose of the directory you're trying to configure? You have mentioned "context root" in your question title, is this what you're after? Typically, Eclipse creates WebContent directory inside the dynamic web project directory for that.Spigot
My problem is that Eclipse seems confused, usually I'd expect the root to be where the compiled files are (bin-directory or equivalent) but with this tomcat project it is somehow set to the folder where my eclipse.exe lies. Even when I try to configure it like I said above. This causes problem when trying to load files.Lichtenfeld
OK. Well, for webapps your compiled classes must go to <WebAppRoot>/WEB-INF/classes there is no getting away from it. When application runs, its "root" may be different - depending where you run it from (e.g. Eclipse will give you the project root, Apache Tomcat will give you something else, relative to its path). If you need to access static resources within your web application, you will need to use relative paths. Try ServletContext.getResourceAsStream(), like here: #866319Spigot
The problem is that any paths given are evaluated relative to eclipse.exe (as shown in my question above). Neither Apache nor my project is anywhere near the eclipse folder. How can I configure eclipse to run my project from my project root folder instead?Lichtenfeld
How do you run your project? Hard to believe the ServletContext#getResourceAsStream() will return anything relative to your eclipse.exe - did you try it? Instead of File#getAbsolutePath() that is.Spigot
Eclipse does not deploy and run your web app from the tomcat webapp directory. The web app is deployed to a path in your workspace similar to ".metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps" that is why you see the directory as "C:/Eclipse".Irade
L
15

Alright, I found a solution.

It seems my default working directory was set to my eclipse folder for the project so i solved it by specifying the project root folder instead which normally is the case.

I configured this here:

Run configurations > Apache Tomcat Run configuration > Arguments tab, under "working directory" choose "other" and specify directory.

Thanks for your comments!

Lichtenfeld answered 10/4, 2012 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.