How to Compile JSP in Eclipse (or other IDE)?
Hey all,
I recently started playing around with JSP and Tomcat- I have both working great, and I've been using a simple text editor to write the JSP files until now.
That works fine, but I'm hoping to move onto a bigger project soon, so continuing to use the simple text editor will be a real exercise in tedium. I've tried opening the .jsp file in eclipse, but I'm unable to see compiler errors or the other eclipse magic such as autocomplete and automatic handling of imports, since I can't figure out how to set up a project for the webapp (I'm using eclipse EE indigo). I've tried googling for this, but everything I try leads me to the same deadend.
I don't really need (or even want to) startup tomcat from eclipse (unless I have to in order to work with the .jsp files), all I really want to do is edit the JSP files in a more efficient way than using a basic text editor.
So my question is, is there a good way to deal with editing of a jsp file or a webapp in general in eclipse, or any other IDE?
Thanks for your time and any help you can provide, as I'm pretty much fumbling in the dark here.
Re: How to Compile JSP in Eclipse (or other IDE)?
I'm not sure there is a better way, so if you find one let me know. JSP files are basically Servlets, and from my understanding are compiled by the container (in your case Tomcat) at runtime. My workflow typically involves running the server, and having the .war 'hot' deployed to test through a browser (pain in the you know what). I know Eclipse has an compile error validator for JSP, its just never served me well enough to rely on it to any great extent.
Re: How to Compile JSP in Eclipse (or other IDE)?
That's what I was afraid of. I was hoping there was a simple solution that allowed for things like showing me what the compile-time errors were before actually running the server and looking at the page in a web browser. Oh well, guess I just have to go back to the old way of doing things without an IDE.
Re: How to Compile JSP in Eclipse (or other IDE)?
Quote:
Originally Posted by
KevinWorkman
So my question is, is there a good way to deal with editing of a jsp file or a webapp in general in eclipse, or any other IDE?
You need to create a Java Dynamic Web project, then Eclipse will compile your JSP pages just like other java classes. You will see compile errors and autocomplete things.
java exception
Re: How to Compile JSP in Eclipse (or other IDE)?
Quote:
Originally Posted by
hns1984
You need to create a Java Dynamic Web project, then Eclipse will compile your JSP pages just like other java classes. You will see compile errors and autocomplete things.
Oh, sweet! This seems to be exactly what I'm looking for. I'll have to play around with it later. Thanks for the tip!
Re: How to Compile JSP in Eclipse (or other IDE)?
For what its worth, web output cannot be viewed this way (that I know of) and I have found that the compile time error feature beyond buggy (perhaps the newer version of Eclipse is better?), the reason my post above says I do not rely on it to any great extent. Your mileage may very.
Re: How to Compile JSP in Eclipse (or other IDE)?
Quote:
Originally Posted by
copeg
For what its worth, web output cannot be viewed this way (that I know of) and I have found that the compile time error feature beyond buggy (perhaps the newer version of Eclipse is better?), the reason my post above says I do not rely on it to any great extent. Your mileage may very.
I'll definitely take that into consideration, but I'm okay with not viewing the web output this way- actually, I came across a ton of solutions trying to launch tomcat from eclipse, but I like to keep everything as separate as possible- I want writing, running, and viewing to be completely independent steps. Just a quirk of mine.
But yeah, I'm already seeing compile-time error weirdness (wrong line numbers) without eclipse, so I'm going to tread cautiously as I add another layer. But this should help with the dumb stuff (basic syntax problems, classpath setup, etc), which is really what I was looking for.
Re: How to Compile JSP in Eclipse (or other IDE)?
Quote:
I came across a ton of solutions trying to launch tomcat from eclipse, but I like to keep everything as separate as possible- I want writing, running, and viewing to be completely independent steps. Just a quirk of mine.
To give you some insight into my workflow that touches on the above (whether or not its best practice I cannot say but it works great for me)...I will typically have 2 servers: test and deployment. The test server I run locally through Eclipse, that facilitates doing all the error and output checking 'offline' - given SWT has browser capability, you might even be able to write a simple Eclipse plugin (or app) for viewing from localhost (if one doesn't already exist). When all is ready, I will deploy it onto the production server, often automating deployment using an ANT task (this is where ANT excels, as it can make the laborious process of compiling, copying, signing, transferring, etc...so simple). I'm probably getting way ahead of what you need now, but I'm just throwing out a few tips keep in mind. The above workflow has really stepped up my game over the past few years.
Re: How to Compile JSP in Eclipse (or other IDE)?
Quote:
Originally Posted by
copeg
To give you some insight into my workflow that touches on the above (whether or not its best practice I cannot say but it works great for me)...I will typically have 2 servers: test and deployment. The test server I run locally through Eclipse, that facilitates doing all the error and output checking 'offline' - given SWT has browser capability, you might even be able to write a simple Eclipse plugin (or app) for viewing from localhost (if one doesn't already exist). When all is ready, I will deploy it onto the production server, often automating deployment using an ANT task (this is where ANT excels, as it can make the laborious process of compiling, copying, signing, transferring, etc...so simple). I'm probably getting way ahead of what you need now, but I'm just throwing out a few tips keep in mind. The above workflow has really stepped up my game over the past few years.
That sounds like a pretty reliable setup. I'm definitely starting from scratch and working my way up- right now I'm only doing local stuff. When I get something worthwhile working (this week's project: registration and login!), I'll investigate hosting and deployment. Then I might try switching to something closer to your setup.