|
When building console applications with Visual MainWin for J2EE you may want to
see the java command line that the application uses. These simple steps show you
how.
Overview
|
|
 |
|
|
Figure 1. Creating a Console Application.
|
With Visual MainWin for J2EE you can develop and build Java Console Applications.
When running these applications, you may want to know the command that is issued
(i.e. java –Classpath [[path to classes]] [[jar file]] [[class to execute]]) so
that you can create shortcuts or other links to execute it from a Windows or Linux
desktop icon. This KnowledgeBase article will show you how you can do this easily.
Create a Simple Console Application
Make sure you have a supported application server running (with the developer edition
you can use Tomcat) and launch Visual Studio.NET. From the File->New->Project dialog,
select the 'Visual MainWin C# for J2EE Projects' folder as shown in Figure 1.
Use this to create a C# console application for J2EE as shown.
This will create a basic console application called 'HelloJavaWorld' with a single
class in it called 'Class1.cs'. Open Class1.cs, and add the following lines to the
main method:
|
|
 |
|
|
Figure 2. Running the Console Application.
|
System.Console.WriteLine("Hello Java World. Press Enter.");
System.Console.ReadLine();
Press F5 to compile and run the application. You should get a screen something like
that in Figure 2.
View the Java Command
Now wouldn’t it be nice to know the correct command to get Java to run this application,
so you don’t have to just do it from Visual Studio.NET?
Here’s how:
Find your C:\Program Files\Mainsoft\Visual MainWin for J2EE\bin folder.
In here, there's a batch file called 'RunTarget.bat'.
In Windows Explorer, right click this file and select 'Edit'.
|
|
 |
|
|
Figure 3. Running the Console Application and inspecting the Java Command.
|
Go to the bottom of the file and you'll see the following text:
:__run
%_javaExe% -cp .; …..
Put a new line between these with the text '@echo on'. It should now look like this:
:__run
@echo on
%_javaExe% -cp .; …..
Save and close this batch file. Now run your application again using F5 within Visual
Studio. See Figure 3.
See the difference? You can now derive the java command line, so that you can create
shortcuts to your console applications from your Windows desktop or start menu! |