U.S. District Judge J. Frederick Motz, who decided in December to issue an injunction against Microsoft, filed the order a day after the companies reached a joint agreement on how it should be implemented.
Microsoft has repeatedly said it will appeal the order to the 4th U.S. Circuit Court of Appeals. Motz said the injunction will not take effect for two weeks to give the appeals court a chance to hear Microsoft's case.
Attorneys from Sun and Microsoft met with Motz last Wednesday to work out details on what the must-carry order would require of Microsoft.
Once the order goes into effect, Microsoft will have four months to put Java on a version of Windows XP.
The order would be in effect while Sun presses its $1 billion antitrust suit claiming Microsoft used its monopoly to hurt Java.
Last week, the two sides disagreed on how and when Java would have to be distributed, so Motz set a timetable of 120 days and specified the version of Windows to be used. Microsoft had sought a six-month deadline.
Motz then urged the two sides to keep working toward an agreement on other details, which they submitted to him Monday.
Java is designed to let programmers write software to run on all types of computers, whether they use Windows, Apple's Mac OS or some other operating system. Users may run into Java without knowing it when they visit Web sites that feature games or other applications.
Sun argues in its lawsuit that Microsoft has gained an unfair advantage by shipping Windows with an outdated version of Java that's inconsistent for its users. Windows is used by more than 90 percent of the world's personal computers.
Part of the antitrust case against Microsoft alleged that the company had deliberately "polluted" the Java language by writing a version of it that was not compatible with other versions, thus reducing its appeal. Microsoft allegedly did this to counter the threat that Java posed to its monopoly over operating systems.
The case is one of four private antitrust lawsuits that followed a federal judge's ruling in a lawsuit filed by the Justice Department and 18 states. The court had found that Microsoft acted as an illegal monopoly based on its dominance in desktop operating systems.
In November, U.S. District Court Judge Colleen Kollar-Kotelly approved a settlement in that case barring Microsoft from retaliating against or threatening computer manufacturers.
The settlement, which two states are appealing, also compels Microsoft to share key technical data with competitors that allow their programs to run more smoothly with Microsoft operating systems.