Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:08:17+00:00 2026-06-14T19:08:17+00:00

I have created a bat file to call a java class. Now I have

  • 0

I have created a bat file to call a java class. Now I have created a GUI in swing. In that swing I have a button as start and for that I have action Listener in which I created the following code

public void actionPerformed(java.awt.event.ActionEvent evt)
{
    try 
    {

        File file = new File("F:/myprog/start.bat");

        Desktop.getDesktop().open(file);

    } catch (IOException e)

    {

        e.printStackTrace();

    }

    jButton1ActionPerformed(evt);

}

When I run click the button I get “Error: Could not find or load main class“

Batch file :

javac *.java
java websphinx.workbench.Workbench
 pause

When I click the bat file the application is running. But from Java program when I call this bat file I get the error. What went wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:08:18+00:00Added an answer on June 14, 2026 at 7:08 pm

    In Java one usually runs a command while Runtime.getRuntime().exec, you’ll need to pass cmd.exe as the file to run, and then the batch name as a parameter.

    try {
         Process p = Runtime.getRuntime().exec(
                        new String[]{"cmd.exe", "/c", "F:/myprog/start.bat"});
         InputStream in = p.getInputStream();
         OutputStream out = p.outputStream();
    } catch (IOException e){
         e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a .bat file that displays all the users logged in Windows
I have created a .bat file that displays a servers terminal Service SessionID and
I have created below bat file to run my RMI server @echo Off set
i have a batch(backup.bat)file.in that i have written a command to create a backup
I have to create a .BAT file that does this: If C:\myprogram\sync\data.handler exists, exit;
I need to capture the output created by a .bat file that is run
Hi I have created a java application and created a jar file. Then I
I have created a batch file for ex(ex.bat) Is it possible to run batch
I have created a bat file which calls selenium server called run-selenium-server.bat which has:
I have created a jar which needs to be called in a bat file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.