Skip to content

Instantly share code, notes, and snippets.

@beamerblvd
Created January 25, 2019 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beamerblvd/dd44652eca5fcca9722e3e630ee8aee2 to your computer and use it in GitHub Desktop.
Save beamerblvd/dd44652eca5fcca9722e3e630ee8aee2 to your computer and use it in GitHub Desktop.
Java 9 Modules split "sub-package" demonstration
package com.example.foo.implone;
import com.example.foo.SalutationProvider;
public final class StandardOutHelloer
{
public static void main(String... arguments)
{
System.out.println(new SalutationProvider().getSalutation());
System.out.flush();
}
}
module com.example.foo.implone {
requires com.example.foo;
exports com.example.foo.implone;
}
package com.example.foo.impltwo;
import com.example.foo.SalutationProvider;
public final class StandardErrHelloer
{
public static void main(String... arguments)
{
System.err.println(new SalutationProvider().getSalutation());
System.err.flush();
System.exit(15);
}
}
module com.example.foo.impltwo {
requires com.example.foo;
exports com.example.foo.impltwo;
}
package com.example.foo;
public class SalutationProvider
{
public SalutationProvider()
{
}
public String getSalutation()
{
return "Hello, World!";
}
}
module com.example.foo {
exports com.example.foo;
}
$ java -Dfile.encoding=UTF-8 -p out/production/com-example-foo-impl1:out/production/com-example-foo -m com.example.foo.implone/com.example.foo.implone.StandardOutHelloer
Hello, World!
$ echo $?
0
$ java -Dfile.encoding=UTF-8 -p out/production/com-example-foo-impl2:out/production/com-example-foo -m com.example.foo.impltwo/com.example.foo.impltwo.StandardErrHelloer
Hello, World!
$ echo $?
15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment