0

I wrote a Java application because the official application is only available for Windows. Because I want to ensure that I don't get into trouble I want to prohibit that it runs on Windows.

What can I check to know if the application runs on Windows and therefore immediately quit the application?

Other advises are welcome, too.

2 Answers 2

2

I'd recommend using the Apache Commons Lang library for this. It has a SystemUtils.IS_OS_WINDOWS, whose purpose is to do this for you. Check this boolean, and if it's set, then use System.exit(1) (or some appropriate value).

It'll save you worrying about whether you're correctly interpreting the result of the System.getProperty() call.

By the way, you might consider getting your application to launch the official application instead of exiting. You could do it either way.

Sign up to request clarification or add additional context in comments.

1 Comment

I have already commons-lang in my project. Otherwise I would do it like @prashant thakre answered.
2

You can use:

System.getProperty("os.name")

If its windows use

System.exit(-1)

1 Comment

I would do it your way, but I already have commons lang in my project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.