Can I compile .java files from Visual Studio?

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
Just curious, I already do all my other programming work there and was wondering if I could integrate my Java work with it instead of using TextPad. Can I add the Java compile tools (mainly, javac.exe) to Visual Studio?

UPDATE 1/21: I did it! And very easily! Surprised no one mentioned this at all. Actually, oog mentioned you could do this, he just didn't give any details.

Basically, it's done the exact same way that TextPad does it, by simply running an .exe with certain parameters from an initial folder. With the .java file open in VS2005, go to Tools > External Tools... . Then Add, name it Compile, for command enter <path>\javac.exe, for Arguments put $(ItemFileName)$(ItemExt), and for Initial directory $(ItemDir). Same thing for Run, only use system32\java.exe, $(ItemFileName) for Arguments, and same for Initial directory.

Then just choose Compile or Run from the Tools menu. Make sure the cursor is within the document at the time of clicking it or it won't work. Works great!
 
Sep 29, 2004
18,656
68
91
Originally posted by: archcommus
Just curious, I already do all my other programming work there and was wondering if I could integrate my Java work with it instead of using TextPad. Can I add the Java compile tools (mainly, javac.exe) to Visual Studio?

GET ECLIPSE!

 

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
Originally posted by: IHateMyJob2004
Originally posted by: archcommus
Just curious, I already do all my other programming work there and was wondering if I could integrate my Java work with it instead of using TextPad. Can I add the Java compile tools (mainly, javac.exe) to Visual Studio?

GET ECLIPSE!
I'm sure it's good but I really don't want another IDE.
 
Sep 29, 2004
18,656
68
91
Originally posted by: archcommus
Originally posted by: IHateMyJob2004
Originally posted by: archcommus
Just curious, I already do all my other programming work there and was wondering if I could integrate my Java work with it instead of using TextPad. Can I add the Java compile tools (mainly, javac.exe) to Visual Studio?

GET ECLIPSE!
I'm sure it's good but I really don't want another IDE.

Why?

If you want to do Javadevelopment, you have two options. Eclipse or NetBeans. Eclipse is far superior.

Anything else is going to lack functionality and have less support.

It's your choice, but I don't think you are being very logical about this. Atleast go to the site and read about Eclipse.
 

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
Originally posted by: IHateMyJob2004
Originally posted by: archcommus
Originally posted by: IHateMyJob2004
Originally posted by: archcommus
Just curious, I already do all my other programming work there and was wondering if I could integrate my Java work with it instead of using TextPad. Can I add the Java compile tools (mainly, javac.exe) to Visual Studio?

GET ECLIPSE!
I'm sure it's good but I really don't want another IDE.

Why?

If you want to do Javadevelopment, you have two options. Eclipse or NetBeans. Eclipse is far superior.

Anything else is going to lack functionality and have less support.

It's your choice, but I don't think you are being very logical about this. Atleast go to the site and read about Eclipse.
I understand that, I was just hoping to use only one IDE if possible. I don't do very complex Java work and really don't need an extremely feature-rich IDE. As of now I just write the code in TextPad and compile and launch right from there. I was wondering if I could at least get those basic capabilities going in Visual Studio.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Yes, it's possible to use Visual Studio as an IDE and configure custom compilation commands for various files. You won't get the full benefits of having an IDE though.
 
Sep 29, 2004
18,656
68
91
Originally posted by: Nothinman
Too bad Eclipse is a resource hog though

I thought "a resource hog" was synonymous with anything involving Java =)

NO NO AND NO

Eclipse is pretty much the standard in the real world for Java development. Net Beans also has a following, but Eclipse has much more plug-in support and is genreally more accepted.

And what is a resource hog when systems today have 3 GHz processors and a gig of memmory? 50 megs of memmory usage is what, 5% of the entire system memmory?

As for bashing Java, the current VMs in many cases actually run Java faster than similar applications because the VMs turn the binaries to byte code for whatever processor they are on, thus running in an optimized manner no matter what type of system you are using.
 
Sep 29, 2004
18,656
68
91
Originally posted by: archcommus
Originally posted by: IHateMyJob2004
Originally posted by: archcommus
Originally posted by: IHateMyJob2004
Originally posted by: archcommus
Just curious, I already do all my other programming work there and was wondering if I could integrate my Java work with it instead of using TextPad. Can I add the Java compile tools (mainly, javac.exe) to Visual Studio?

GET ECLIPSE!
I'm sure it's good but I really don't want another IDE.

Why?

If you want to do Javadevelopment, you have two options. Eclipse or NetBeans. Eclipse is far superior.

Anything else is going to lack functionality and have less support.

It's your choice, but I don't think you are being very logical about this. Atleast go to the site and read about Eclipse.
I understand that, I was just hoping to use only one IDE if possible. I don't do very complex Java work and really don't need an extremely feature-rich IDE. As of now I just write the code in TextPad and compile and launch right from there. I was wondering if I could at least get those basic capabilities going in Visual Studio.

Want to learn how things are done in industry, get Eclipse. It's good for your resume. If you are just toying with software, it sounds like Textpad is good enough. I highly doubt MS would put java in VS on their own and any plug-ins that might exist probably suck because I have never heard a single perosn in industry even mntion it as a possiblity.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: IHateMyJob2004
Want to learn how things are done in industry, get Eclipse. It's good for your resume. If you are just toying with software, it sounds like Textpad is good enough. I highly doubt MS would put java in VS on their own and any plug-ins that might exist probably suck because I have never heard a single perosn in industry even mntion it as a possiblity.
No offence, but you're really not doing him any good here by suggesting he not do it in VS. Quite clearly it's as capable as Textpad for editing and I'm sure it's flexible enough to be able to run some compilation scripts and it'll save him from having to fire up another program.

Archcommus, sorry for the thread crap, I don't know how to compile/run java programs from VS, I just wanted to say something about the silliness of recommending eclipse here.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
You used to be able to specify custom translation tools for source modules right in the project settings (or possibly the global options, I can't recall). I'd be surprised if you can't still do that in 2005, but I wasn't able to find it in a quick search. I have no doubt you could do it with a build script.
 

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
Originally posted by: kamper
Originally posted by: IHateMyJob2004
Want to learn how things are done in industry, get Eclipse. It's good for your resume. If you are just toying with software, it sounds like Textpad is good enough. I highly doubt MS would put java in VS on their own and any plug-ins that might exist probably suck because I have never heard a single perosn in industry even mntion it as a possiblity.
No offence, but you're really not doing him any good here by suggesting he not do it in VS. Quite clearly it's as capable as Textpad for editing and I'm sure it's flexible enough to be able to run some compilation scripts and it'll save him from having to fire up another program.

Archcommus, sorry for the thread crap, I don't know how to compile/run java programs from VS, I just wanted to say something about the silliness of recommending eclipse here.
Not a thread crap at all, kamper. IHateMyJob2004, I understand your points but as I've already said, I DON'T work on huge Java projects and so I DON'T need an IDE that is considered the "industry standard." Hell, at work I don't even use Java, I use VB and C#. Considering TextPad has been sufficient for my Java work so far, I'm sure VS2005 could be as well. So if I could figure out a way to integrate the compile (javac.exe) and launch (java.exe) tools that'd be great.
 

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
Originally posted by: Markbnj
You used to be able to specify custom translation tools for source modules right in the project settings (or possibly the global options, I can't recall). I'd be surprised if you can't still do that in 2005, but I wasn't able to find it in a quick search. I have no doubt you could do it with a build script.
Can you detail what a "build script" is exactly?
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
Interesting :) anyone know?

I used netbeans before but its WYSIWYG suck! big time. often incorrect codes are generated... I'll give eclipse a try but if there is a way to integrate into vs then that would be great :)
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: archcommus
Can you detail what a "build script" is exactly?
A script that builds your java files. It could be a batch script that just calls javac or it could be an ant script that involves something more complex. Either way, you'd just be plugging some kind of command-line command into vs. The same would apply for running the code.
 

blackllotus

Golden Member
May 30, 2005
1,875
0
0
Originally posted by: IHateMyJob2004
As for bashing Java, the current VMs in many cases actually run Java faster than similar applications because the VMs turn the binaries to byte code for whatever processor they are on, thus running in an optimized manner no matter what type of system you are using.

I've never heard of a case where a JIT optimizer outperforms the optimizer in a "normal" compiler.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: blackllotus
Originally posted by: IHateMyJob2004
As for bashing Java, the current VMs in many cases actually run Java faster than similar applications because the VMs turn the binaries to byte code for whatever processor they are on, thus running in an optimized manner no matter what type of system you are using.
I've never heard of a case where a JIT optimizer outperforms the optimizer in a "normal" compiler.
I think it's still largely theoretical, or limited to very specific conditions, but it will happen.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: archcommus
Originally posted by: Markbnj
You used to be able to specify custom translation tools for source modules right in the project settings (or possibly the global options, I can't recall). I'd be surprised if you can't still do that in 2005, but I wasn't able to find it in a quick search. I have no doubt you could do it with a build script.
Can you detail what a "build script" is exactly?

What Kamper said. In the case of MS Build, which is the build manager behind Visual Studio, it uses XML configuration files to manage the build process.
 

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
I did it! And very easily! Surprised no one mentioned this at all. Actually, oog mentioned you could do this, he just didn't give any details.

Basically, it's done the exact same way that TextPad does it, by simply running an .exe with certain parameters from an initial folder. With the .java file open in VS2005, go to Tools > External Tools... . Then Add, name it Compile, for command enter <path>\javac.exe, for Arguments put $(ItemFileName)$(ItemExt), and for Initial directory $(ItemDir). Same thing for Run, only use system32\java.exe, $(ItemFileName) for Arguments, and same for Initial directory.

Then just choose Compile or Run from the Tools menu. Make sure the cursor is within the document at the time of clicking it or it won't work. Works great!
 

archcommus

Diamond Member
Sep 14, 2003
8,115
0
76
One thing I'm curious about, how does VS know what are proper class and keyword names in a Java file to properly color code it? VS was never set up for Java so I don't know how it knows. It does do it properly though and I am impressed.
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
Originally posted by: archcommus
One thing I'm curious about, how does VS know what are proper class and keyword names in a Java file to properly color code it? VS was never set up for Java so I don't know how it knows. It does do it properly though and I am impressed.

They may have included some limited parsing support. The syntax is VERY similar to C++, so it would take only minor tweaks to at least get class/keyword/function/comment/variable highlighting.

Re: JIT compilation -- where it can help you is primarily when you don't know what kind of processor you will be executing on. You can build a 'generic' x86 executable from C/C++, but sometimes you can gain some performance by optimizing specifically for, say, running on an Athlon64. If you want to do that in C/C++, you need to provide a different binary executable (or at least a different set of modules/DLLs) for each processor type. A JIT-compiled language can (in theory) adapt on the fly.