Yes, you heard me right. I find that as a contractor I am constantly going from one editor to another. Each has their advantages, but when it comes to working on a Window's platform, I find that Visual Studio .NET gives me a lot and it is something I am comfortable with. I can write .NET apps, C++ applications, and C# programs, all within the same editor.
Recently, I needed to go back to editing some Java and JSP code. Although the final platform was to be a Linux flavor, the development environment was on Windows XP Professional. "Hey," I thought. "Why not use Visual Studio to edit my Java code?"
After a bit of research, here is what I came up with. The steps are three-fold:
- Find a way to fool Visual Studio into thinking that when it is editing a JSP file, it should treat it as if it were an ASP file. This would include syntax colorizing, tabs, auto formatting, etc., all according to the Options I've set in my editor.
- Find a way to fool Visual Studio into thinking that when it is editing a Java file, it should treat it as if it were an C++/C# file. Like above, this would use all the Options I've set in my editor.
- Find out how I can make Visual Studio recognize the key words in my documents so that it will colorize the correct syntax.
Here is what I did:
1. Enter some stuff into the registry. (A note for first-timers: Playing with the registry is dangerous stuff. Not as dangerous as playing with dynamite or kissing a redhead, but you get my drift. If you don't feel comfortable in the registry, call in a favor on a friend of yours who does and can handle the risk. The last thing I want is some whiny email regarding you doing something beyond your ability to handle. 'Nuff said.
a. Click Start and then Run. Type in "regedit" as the program to open (or use your own favorite registry editor).
b. Navigate to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions"
c. Create a new key by right-clicking on "File Extensions" and selecting New | Key. Nave it ".java".
d. Right click on the "(Default)" entry and choose Modify.
e. In the Value data field, enter the following:
{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}
Astute readers will note that this is the same Default entry you will find in the area under the ".cpp" extension.
Voila! Step number one is complete!
2.Step number two is similar, except this time we need to enter the .jsp extension with the .asp-like entry. Here's how:
a. Click Start asnd then Run. Type in "regedit" as the program to open (or use your own favorite registry editor).
b. Navigate to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions"
c. Create a new key by right-clicking on "File Extensions" and selecting New | Key. Nave it ".jsp".
d. Right click on the "(Default)" entry and choose Modify.
e. In the Value data field, enter the following:
{58E975A0-F8FE-11D2-A6AE-00104BCC7269}
Again, you may note that this is the same Default entry you will find in the area under the ".asp" extension.
3. Fine and well. You now can edit .java and .jsp files in Visual Studio. But you may notice that the .java files will be colorizing some of the wrong words, and leaving other Java keywords alone. What gives? The problem here is that Visual Studio was designed to colorize C# and C++ keywords, so you are out of luck when it comes to Java keywords that don't match up to the C++/C# words. To solve this, we need to address step number three. Here goes:
a. Create a file called "usertype.dat" and place it in your IDE directory. I installed with the default options and found mine at "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE". Your results may differ.
b. In this file, add all of the keywords for Java, separated by a hard-return after each. For example, here is mine:
abstract
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
extends
false
final
finally
float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
strictfp
String
super
switch
synchronized
this
throw
throws
transient
true
try
void
volatile
while
c. Save it and your done! Next time you open Visual Studio and load a .java file, you should see all of the Jva keywords colorized according to your preferences.
Did you appreciate this tip? Good, you can send me lots of money!
Seriously, I believe information is like manure; if you don't spread it around, it stinks. Work it back into the community, and all kinds of great things can grow.