Under Eclipse, use Runtime.getruntime (). exec Start ja

Source: Internet
Author: User

Under the WINDOW7 System experiment (Linux under Path format is not the same as under Windows) Eclipse uses Runtime.getruntime (). exec Start ja

Runtime.getruntime (). EXEC ("Java My_program"); System.exit (0); Which would start a whole new JVM running your program, and then kill the original. Not exactly pretty or efficient, but it would restart it.

Today in Eclipse wrote the use of Runtime.getruntime (). EXEC ("Java MyTest"); To start a new Java program, but could not start the MyTest class.

1. This program can be fully functional in CMD. So I copied the mytest.class (except the package name) to the root of the project and suddenly found that the MyTest program started

The

I came to the conclusion that when using Runtime.getruntime (). exec to start other Java programs, the Java Virtual machine starts looking for this class at the root of the project, and this class actually exists under the bin directory. At this time, as long as the command to add Classpath settings information can be, plus the package name.

The last modified code is as follows:

2. Runtime.getruntime (). EXEC ("Java-classpath h:\\workspace\\javawork\\bin cn.itcast.io.MyTest");

Or

3.runtime.getruntime (). EXEC ("Java-classpath./bin cn.itcast.io.MyTest"); . Represents the current directory.

Or

4.runtime.getruntime (). EXEC ("Java-classpath bin Cn.itcast.io.MyTest");

The program runs normally!

Original: http://blog.sina.com.cn/s/blog_6b96eae10100ok01.html

Under Eclipse, use Runtime.getruntime (). exec Start ja

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.