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 6769263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:10:20+00:00 2026-05-26T15:10:20+00:00

I had created a class which create process using ProcessBuilder and then launch process

  • 0

I had created a class which create process using ProcessBuilder and then launch process

ProcessBuilder pb = new ProcessBuilder("mvn","exec:java","-Dexec.mainClass="+"FunnyClass");

Now when I m running this class on linux box, it run fine, but on windows it give me error, stating something like ‘mvn’ not found, I need to change to

ProcessBuilder pb = new ProcessBuilder
                       ("mvn.bat","exec:java","-Dexec.mainClass="+"FunnyClass");

But if I am running command on command prompt “mvn exec:java -Dexec.mainClass=FunnyClass”, it run fine. So why I need to give mvn.bat in processbuilder.

Is there any solution to it?

my java application is going to run on both windows & linux boxes, So what should I do?

  • 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-05-26T15:10:20+00:00Added an answer on May 26, 2026 at 3:10 pm

    This happens because the windows shell (cmd) has a feature: it tries to add extensions exe, ‘bat’, ‘cmd’ to command line you are running. Once it finds the first match (i.e. file that really exists in file system) it runs it.

    In case of maven you have unix shell script mvn that cannot be executed on windows and windows batch file ‘.bat’. Command prompt adds ‘.bat’ to ‘mvn’ that you type in command prompt, sees that the file exists and runs it.

    When you are running process from java you do not have shell, so no-one does this job.
    I’d suggest you to check the operating system and hold command per OS. If you want clear solution create resource file cmd.properties:

    mvn.windows = mvn.bat
    mvn.unix = mvn
    

    Now check OS using system property os.name and create command using data from cmd.properties.

    Alternative solutionis to run command using cmd /c on windows and ‘/bin/sh -c’ on unix but it does not simplify anything, so I’d avoid this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently had an idea to create my own String class to make using
Using Java, I have a class which retrieves a webpage as a byte array.
For this assignment I had to create my own string class. I initially wrote
So for my programming class we have had a project to create a virtual
I have a C# class which needs to process a sequence of items (
Here is my custom logger class, which helps me create logs file in my
I'm trying to create a generic class which will have some static functions based
I have created a C++-wrapper (a class) for a larger C codebase which was
My code is working so far but I had to create a Class for
I've created an add-in, which call via Reflection, a WPF Class Library. Since this

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.