Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Using Java Classes in Windows Batch Files

Using Java Classes in Windows Batch Files - a simple approach for system admin Although Java is an ideal language for implementing rich GUI applications, it is equally well-suited for the development of small console-based programs that, in turn, are p

Tutorial Details:

Implementing Console-Based Programs in Java
Fortunately, Java resembles C and C++ in many aspects. In particular, Java programs meet all of the requirements of console-based applications. To repeat, these are:

The ability to access the standard input, standard output, and standard error channels.
The ability to access the arguments that were passed upon startup.
The ability to provide a result (i.e., an exit code).
Taking this into account, Java seems a natural choice for console-based applications. There is one important drawback, though. Since the standard Java compiler (javac) produces byte code, there is no .exe file that we can put into our bin folder. The usual way to run a Java application from the command-line prompt is to invoke the Java runtime, passing it the name of the class containing the main method or a .jar file (with a manifest file that mentions where main is) to launch, plus additional arguments that will be passed to the program. Though this is perfectly OK for program-launcher scripts, it is inconvenient when writing shell scripts, since the preferred approach is to simply write a program name and pass arguments to it. In our case, this would be the class name. To solve this, we have two options:

Make them (or at least a part of them) native executables.
Make Windows think they are native.
Which approach is best for you depends on what you wish to do with your programs. There are many tools available that can transform classes into native .exe files or put wrappers around them. For example, java.net recently featured an interesting series of articles by Joshua Marinacci about how to Make Your Swing App Go Native. In this second part of the series, Joshua introduced a commercial tool called JexePack that creates native executables with unique program icons. Such wrapper programs actually launch the Java interpreter, which in turn runs the Java program. This is certainly great if your programs have to look professional; for instance, because you plan to distribute them. So theoretically, we might use this tool for our purposes as well, but this implies that for each Java class we plan to use in a batch file, we need to create an appropriate native wrapper.

Another (at least theoretical) possibility is to use the GNU Compiler for the Java Programming Language, which can create native binaries. However, installing and using the GNU Compiler Collection on a Windows-based machine is far beyond the scope of this article. So let us analyze the second approach.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Using Java Classes in Windows Batch Files

View Tutorial:
Using Java Classes in Windows Batch Files

Related Tutorials:

Commercial applications with Java
Commercial applications with Java
 
Getting started with Java 2D - JavaWorld - July 1998
Getting started with Java 2D - JavaWorld - July 1998
 
To jar or not to jar? - JavaWorld - July 1998
To jar or not to jar? - JavaWorld - July 1998
 
The Volano Report: Which Java platform is fastest, most scalable? A JavaWorld exclusive! - JavaWorld - Mar
The Volano Report: Which Java platform is fastest, most scalable? A JavaWorld exclusive! - JavaWorld - March 1999
 
Java Tip 72: Press Escape to close your Swing dialog windows
Java Tip 72: Press Escape to close your Swing dialog windows
 
Java Tip 85: Fun and games with JFileChooser - JavaWorld
Java Tip 85: Fun and games with JFileChooser - JavaWorld
 
A ZipClassLoader for automated application distribution - JavaWorld April 2000
A ZipClassLoader for automated application distribution - JavaWorld April 2000
 
Automate your build process using Java and Ant - JavaWorld October 2000
Automate your build process using Java and Ant - JavaWorld October 2000
 
Introduction to the Java Mail API
Introduction to the Java Mail API
 
Think small: Java on Compaq's iPAQ
Think small: Java on Compaq's iPAQ
 
Deploy code servers in Jini systems
Deploy code servers in Jini systems
 
Picture this
Picture this
 
The State of JAXB: Availability, Suitability, Analysis, and Architecture
The State of JAXB: Availability, Suitability, Analysis, and Architecture When working with XML in OO languages, there is little doubt that objects provide distinct advantages as compared to SAX, DOM, or raw XML. This process of working with XML and obj
 
JSmooth
JSmooth JSmooth creates standard Windows executable files (.exe) that smartly launch java applications.
 
Using Java Classes in Windows Batch Files
Using Java Classes in Windows Batch Files - a simple approach for system admin Although Java is an ideal language for implementing rich GUI applications, it is equally well-suited for the development of small console-based programs that, in turn, are p
 
Wakeonlan
What is wakeonlan? wakeonlan is a small OS independent java program that sends 'magic packets' to wake-on-lan enabled ethernet adapters and motherboards in order to switch on the called machine.It runs on every machine with an installed 1.4 java runtime.
 
InfoNode (Java Components)
InfoNode Docking Windows is a pure Java Swing based docking windows framework. The best way to see features of InfoNode Docking Windows is to try the Web Start demos.
 
Commons Launcher
The Launcher Component is designed to be a cross platform Java application launcher.
 
JLAN Server v3.3
JLAN Server v3.3 JLAN Server is a high performance JavaTM based file server supporting Windows file sharing (SMB/CIFS), NFS and FTP protocols. Write your own virtual filesystems with the core server handling all protocol exchanges with the client. Incl
 
Clean Up Your Mess: Managing Temp Files in Java Apps
Clean Up Your Mess: Managing Temp Files in Java Apps Creating and managing temporary files in a Java application can be a little tricky due to some open JVM bugs. Develop a workaround with some custom code and a clever design.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.