AllExperts > Experts 
Search      

Java

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Java Answers
Question Library

Ask a question about Java
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Artemus Harper
Expertise
I have a BS in computer science and am working towards a Masters degree.

Experience
I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection, and Java java.nio.* knowledge of Java bytecode and annotations. Basics in c++ and c#
 
   

You are here:  Experts > Computing/Technology > Focus on Java > Java > .bat file

Topic: Java



Expert: Artemus Harper
Date: 5/25/2008
Subject: .bat file

Question
QUESTION: i want to create a .bat file for my project so that i can double click on it and execute it.
i tried creating it but it didnt worked. the command prompt pops up,
i added these 2 lines
javac *.java
java SpiderControl.java

here SpiderControl has the main function.is these lines are sufficient or i am doing some mistake. kindly tell me the complete code for it.



ANSWER: The java command does not take the name of the source program as you have suggested, but rather the fully qualified class name.

E.g.
If you class was:
public class SpiderControl
{
  public static void main(String[] args)
  {
    ...
  }
}

you would use:
java SpiderControl

If you had a package decleration:
package myclasses.gui;

public class SpiderControl
{
  public static void main(String[] args)
  {
    ...
  }
}

Then it would be:
java mclasses.gui.SpiderControl

Also, you don't need to have javac compile all files, it will determine what to compile by simply giving your main program.

---------- FOLLOW-UP ----------

QUESTION: ok.now i tried
javac SpiderControl.java
java SpiderControl
but these 2 lines are again not working.the command window pops up but again closes whithout displaying the interface.what to do now??

Answer
You might have the classpath configured incorrectly, or the batch file is not opening in the correct directory. Instead of simply double clicking the command prompt, you should open a command window, try running the batch file, and see if there is any error.

You can probably correct this, by adding a cd command to the directory where you have the compiled .class files. You can change the directory to the current bat file directory with:
cd /d %~d0%~p0

you can also add a pause command so the window pauses before exiting.

If the directory is correct, then you classpath is set to something other than the default, so you would want to change:

java SpiderControl
to
java -cp . SpiderControl

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.