Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _clojure_jvm/02_basic_java.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ on the classpath. This can be done with the `-classpath` option to the `java` co

change back to the parent directory where the `Hello.java` file is defined

$ cd
$ cd ..

### System classes

Expand Down
8 changes: 4 additions & 4 deletions _clojure_jvm/03_class_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Methods which return a value use the grammar for field descriptors to denote the
Method descriptors consist of a literal `(`, the corresponding field descriptor for each parameter type in sequence, a literal `)` followed by the return type descriptor. This can be either `V` for `void` methods,
or a field descriptor for the return type.

For example the method `public String test(int i, boolean b, Object o)` has a method descriptor of `(IZLjava/lang/Object;)java/lang/String;`.
For example the method `public String test(int i, boolean b, Object o)` has a method descriptor of `(IZLjava/lang/Object;)Ljava/lang/String;`.

## Constant pool contents

Expand All @@ -118,7 +118,7 @@ Here are the references made by the `test.Hello` class:
| #1 | `java/lang/Object::<init>` | Method | Object constructors are given the special name `<init>` within `.class` files. This is invoked by the `test.Hello` constructor (see below). |
| #8 | `java/lang/System` | Class | Class which defines the static `out` field |
| #7 | `java/lang/System::out` | Field | Reference to the `out` field of the `java.lang.System` class |
| #12 | `Ljava/io/PrintStream` | Type reference | The declared type of the `System.out` field |
| #12 | `Ljava/io/PrintStream;` | Type reference | The declared type of the `System.out` field |
| #13 | | String | The string constant "Hello world!" |
| #16 | `java/io/PrintStream` | Class | Type defining the `println` method |
| #15 | `java/io/PrintStream::println` | Method | The `println` method used to write to the console |
Expand Down Expand Up @@ -206,7 +206,7 @@ The [getstatic](https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-6.html#
`System.out` field within the constant pool of the `test.Hello` class.

The literal string "Hello world!" is pushed onto the operand stack with the [ldc](https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-6.html#jvms-6.5.ldc) instruction. The operand of
`#15` is the index of the string within the class constant pool.
`#13` is the index of the string within the class constant pool.

At this point the operand stack contains the arguments to the `java.io.PrintString.<println>` method - the receiver (the contents of the `System.out` field), and the string to write. The
At this point the operand stack contains the arguments to the `java.io.PrintStream.<println>` method - the receiver (the contents of the `System.out` field), and the string to write. The
method is invoked with [invokevirtual](https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-6.html#jvms-6.5.invokevirtual) using the method reference in the class constant pool.
6 changes: 3 additions & 3 deletions _clojure_jvm/04_jar_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ __src/libhello/MessageSink.java__

In addition, we define a source of messages read from the command-line, and a sink which writes messages a `PrintStream`:

__src/libhello/CommandLinkMessageSource.java__
__src/libhello/CommandLineMessageSource.java__
```java
{% include code/jar/src/libhello/CommandLineMessageSource.java %}
```
Expand All @@ -56,7 +56,7 @@ jar --create --file libhello.jar -C classes/libhello .

this creates a `libhello.jar` file in the current directory. We can list the contents of this file with the `--list` command:

jar --lib --file libhello.jar
jar --list --file libhello.jar

This shows the archive contains the `.class` files as their expected locations on the classpath, along with a `META-INF/MANIFEST.MF` file.
This file is called the `_manifest` file and is described [below](#manifest-files).
Expand Down Expand Up @@ -163,7 +163,7 @@ We can now build the new JAR:

and run it with the `-jar` option as before:

> java --jar echo-uber.jar Hello world '!'
> java -jar echo-uber.jar Hello world '!'

### File collisions

Expand Down
5 changes: 3 additions & 2 deletions _clojure_jvm/05_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We fetch the JSON library JAR locally and begin work:

after a frenetic caffeine-fueled 10-hour coding session, we finally have our new message source implementation:

__JSONMessageSource.java__
__src/libhello/JSONMessageSource.java__
```
{% include code/java_dependencies/JSONMessageSource.java %}
```
Expand Down Expand Up @@ -171,6 +171,7 @@ json-test/
test/
EchoJSON.java
pom.xml
messages.json
```

**pom.xml**
Expand All @@ -192,7 +193,7 @@ classpath from Maven and supply that to run the application:

```
mvn dependency:build-classpath -Dmdep.outputFile=classpath.txt
java -cp $(cat classpath.txt):target/json-test-1.0.0.jar test.EchoJSON messages.json
java -cp "$(cat classpath.txt):target/json-test-1.0.0.jar" test.EchoJSON messages.json
```

If we look in the `classpath.txt` file written by the `mvn` command we can see it references all transitive dependencies of the application
Expand Down
6 changes: 3 additions & 3 deletions _clojure_jvm/06_common_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ an application is created which uses the newer version:
compiling both class versions and the application against the newer version

```
pushd version1 && javac Greet.java && popd
pushd version2 && javac Greet.java && popd
pushd version1 && javac Greeter.java && popd
pushd version2 && javac Greeter.java && popd
javac -cp .:version2 GreetApp.java
```

Expand Down Expand Up @@ -137,7 +137,7 @@ public class MySqlMessageSourceFactory implements MessageSourceFactory { ... }

these would then be listed as implementation classes within the corresponding interface service file:

**META-INF/services/com.picosoft.messaging**
**META-INF/services/com.picosoft.messaging.MessageSourceFactory**
```
com.picosoft.messaging.db.PostgresMessageSourceFactory
com.picosoft.messaging.db.MySqlMessageSourceFactory
Expand Down
2 changes: 1 addition & 1 deletion _clojure_jvm/07_evaluating_clojure.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ classpath the namespace could be defined in. The conversion process is as follow

1. Convert any `.` characters in the namespace name to `/`s
2. Convert any `-` characters in the namespace name to `_`s
3. Add `.clj`, `.cljc` and `.__init.class` to the resulting name
3. Add `.clj`, `.cljc` and `__init.class` to the resulting name

This means there are three candidate locations a namespace could be loaded from. Applying the process to the namespace
`org.picosoft.lib-hello.core` the candidate locations are:
Expand Down
4 changes: 2 additions & 2 deletions _clojure_jvm/08_compiling_clojure.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ The fat JAR can then be built with
```
> mkdir classes uber
> unzip -d uber clojure-1.11.1.jar
> unzip -d -o -d uber/ core.specs.alpha-0.2.62.jar
> unzip -d -o -d uber/ spec.alpha-0.3.218.jar
> unzip -o -d uber/ core.specs.alpha-0.2.62.jar
> unzip -o -d uber/ spec.alpha-0.3.218.jar
> java -cp clojure-1.11.1.jar:core.specs.alpha-0.2.62.jar:spec.alpha-0.3.218.jar:classes:src clojure.main -e "(compile 'greet.main)"
> cp -r classes/* uber/
> cp -r src/* uber/
Expand Down
12 changes: 6 additions & 6 deletions _clojure_jvm/09_deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ on the classpath since that is where our application namespaces are defined. Def
{% include code/deps/basic/src/greet/main.clj %}
```

The `clojure` CLI allows us to invoke `clojure.main` with the project classpath with the `-m` option:
The `clojure` CLI allows us to invoke `clojure.main` with the project classpath with the `-M` option:

```
> clojure -m greet.main everyone
> clojure -M -m greet.main everyone
Hello everyone!
```

you can display the computed classpath with

```
> clojure -Spath
src:~/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar:~/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar:...
src:~/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar:...
```

as expected, it contains our `src` directory and the JAR files for the Clojure JAR and all its dependencies.
Expand All @@ -76,7 +76,7 @@ If you open the first of these (the system project file) you will see it has def

**/install/dir/deps.edn**
```clojure
{:path ["src"]
{:paths ["src"]
:deps {
org.clojure/clojure {:mvn/version "1.11.1"}
}
Expand Down Expand Up @@ -150,15 +150,15 @@ add it as a Git dependency rather than depend on the published JAR. This results
This can then be run as before:

```
> clojure -m greet.main --excite everyone
> clojure -M -m greet.main --excite everyone
Hello everyone!
```

If you look at the classpath for this project:

```
> clojure -Spath
src:~/.gitlibs/libs/clojure/tools.cli/23ee9655fab71cef253a51d1bce3e7b2327499a3/src/main/clojure:~/projects/greet/lib/src
src:~/.gitlibs/libs/clojure/tools.cli/23ee9655fab71cef253a51d1bce3e7b2327499a3/src/main/clojure:...:~/projects/greet/lib/src:...
```

You can see the `tools.cli` repository was cloned locally under `~/.gitlibs` and the local project source directory was placed on the classpath.
Expand Down