Skip to content

Commit

Permalink
Content clarifications and markdown fixes for consistency with other …
Browse files Browse the repository at this point in the history
…tutorials.

PiperOrigin-RevId: 467411049
Change-Id: I2b49a9cdf2ff04e058a0a379fc80c4a8ab4e993c
  • Loading branch information
Googler authored and Copybara-Service committed Aug 13, 2022
1 parent 4185b59 commit 61c433e
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions site/en/tutorials/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ you don't have it installed already.

Retrieve the sample project from Bazel's GitHub repository:

```sh
git clone https://github.com/bazelbuild/examples
```posix-terminal
$ git clone https://github.com/bazelbuild/examples
```

The sample project for this tutorial is in the `examples/java-tutorial`
Expand Down Expand Up @@ -128,8 +128,8 @@ instead of listing them one by one.)
To build your sample project, navigate to the `java-tutorial` directory
and run:

```
bazel build //:ProjectRunner
```posix-terminal
$ bazel build //:ProjectRunner
```
In the target label, the `//` part is the location of the `BUILD` file
relative to the root of the workspace (in this case, the root itself),
Expand All @@ -152,8 +152,8 @@ through its contents to get an idea for Bazel's output structure.

Now test your freshly built binary:

```sh
bazel-bin/ProjectRunner
```posix-terminal
$ bazel-bin/ProjectRunner
```

### Review the dependency graph
Expand All @@ -166,8 +166,8 @@ To visualize the sample project's dependencies, you can generate a text
representation of the dependency graph by running this command at the
workspace root:

```
bazel query --notool_deps --noimplicit_deps "deps(//:ProjectRunner)" --output graph
```posix-terminal
$ bazel query --notool_deps --noimplicit_deps "deps(//:ProjectRunner)" --output graph
```

The above command tells Bazel to look for all dependencies for the target
Expand All @@ -176,7 +176,6 @@ output as a graph.

Then, paste the text into [GraphViz](http://www.webgraphviz.com/).


As you can see, the project has a single target that build two source files with
no additional dependencies:

Expand Down Expand Up @@ -217,8 +216,8 @@ the `greeter` library is required to build the `ProjectRunner` binary.

To build this new version of the project, run the following command:

```
bazel build //:ProjectRunner
```posix-terminal
$ bazel build //:ProjectRunner
```

Bazel produces output similar to the following:
Expand All @@ -233,8 +232,8 @@ INFO: Elapsed time: 2.454s, Critical Path: 1.58s

Now test your freshly built binary:

```
bazel-bin/ProjectRunner
```posix-terminal
$ bazel-bin/ProjectRunner
```

If you now modify `ProjectRunner.java` and rebuild the project, Bazel only
Expand Down Expand Up @@ -296,8 +295,8 @@ java_library(
Now you can build the new package by running the following command at the root
of the workspace:

```
bazel build //src/main/java/com/example/cmdline:runner
```posix-terminal
$ bazel build //src/main/java/com/example/cmdline:runner
```

Bazel produces output similar to the following:
Expand All @@ -312,8 +311,8 @@ Target //src/main/java/com/example/cmdline:runner up-to-date:

Now test your freshly built binary:

```
./bazel-bin/src/main/java/com/example/cmdline/runner
```posix-terminal
$ ./bazel-bin/src/main/java/com/example/cmdline/runner
```

You've now modified the project to build as two packages, each containing one
Expand Down Expand Up @@ -359,8 +358,8 @@ As you remember, the [java_binary](/reference/be/java#java_binary) build rule
produces a `.jar` and a wrapper shell script. Take a look at the contents of
`runner.jar` using this command:

```
jar tf bazel-bin/src/main/java/com/example/cmdline/runner.jar
```posix-terminal
$ jar tf bazel-bin/src/main/java/com/example/cmdline/runner.jar
```

The contents are:
Expand All @@ -380,8 +379,8 @@ won't run standalone on another machine. Fortunately, the `java_binary` rule
allows you to build a self-contained, deployable binary. To build it, append
`_deploy.jar` to the target name:

```
bazel build //src/main/java/com/example/cmdline:runner_deploy.jar
```posix-terminal
$ bazel build //src/main/java/com/example/cmdline:runner_deploy.jar
```

Bazel produces output similar to the following:
Expand All @@ -394,7 +393,25 @@ INFO: Elapsed time: 1.700s, Critical Path: 0.23s
```
You have just built `runner_deploy.jar`, which you can run standalone away from
your development environment since it contains the required runtime
dependencies.
dependencies. Take a look at the contents of this standalone JAR using the
same command as before:

```posix-terminal
$ jar tf bazel-bin/src/main/java/com/example/cmdline/runner_deploy.jar
```

The contents include all of the necessary classes to run:

```
META-INF/
META-INF/MANIFEST.MF
build-data.properties
com/
com/example/
com/example/cmdline/
com/example/cmdline/Runner.class
com/example/Greeting.class
```

## Further reading

Expand Down

0 comments on commit 61c433e

Please sign in to comment.