Forums Register Login

Running class from cmd line best practice?

+Pie Number of slices to send: Send
What is the preferred way to run part of a package from the cmd line? In the past I have just used the main() method in one of the existing classes. However I don't think this is the best way since I need to use multiple classes from my codebase.

What is the preferred way to do this?
+Pie Number of slices to send: Send
No problem. Just make sure all the classes your program needs are in the classpath. The main() method is only needed in the first class that gains control when executed.
+Pie Number of slices to send: Send
I usually create a Windows batch file (.bat, .cmd) to go along with the Java distribution. On *nix systems I create shell scripts. So, on the command line I type the name of the batch file and let it launch the Java program.
+Pie Number of slices to send: Send
As long as all the other classes are accessible from the location of the main method, the JVM will be able to find them; there is a program called a class loader (and there are ClassLoader classes) which do that. Obviously all the classes must be compiled first.
+Pie Number of slices to send: Send
 

Carey Brown wrote:I usually create a Windows batch file (.bat, .cmd) . . . On *nix systems I create shell scripts. . . .

Good idea which will allow you to compile multiple classes simultaneously, presumably.

Would you show us an example of such a file, please.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:

Carey Brown wrote:I usually create a Windows batch file (.bat, .cmd) . . . On *nix systems I create shell scripts. . . .

Good idea which will allow you to compile multiple classes simultaneously, presumably.

Would you show us an example of such a file, please.



filefind.bat

@echo off
java -classpath c:\bin\app_file\libs\csbutils.jar;c:\bin\app_file\filefind.jar FileFind %*
+Pie Number of slices to send: Send
Thank you

That means you stop the command line echoing its instructions, and execute the java command to run the main method in the FindFile class using scbutils and findfile .jar files in the classpath.
I found that %* means all the command line arguments

That Last Link wrote:does %* in batch file mean all command line arguments?

. . .

Yes. According to the official Microsoft documentation:

The %* batch parameter is a wildcard reference to all the arguments, not including %0, that are passed to the batch file.

 
+Pie Number of slices to send: Send
I guess I wasn't questioning whether it would run, more of what is the best practice for this. Here is my class to give more insight.

There's a city wid manhunt for this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 514 times.
Similar Threads
how do I save values across methods
JNLP mutiple JAR launching issue
Answers to IBM 486 sample test
Tomcat questions concerning ROOT.xml and implications of changes to it
How does Architecture fit with Agile?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:50:41.