Skip to content
Open
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
11 changes: 1 addition & 10 deletions content/doc/applications/java/java-gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,7 @@ Example:
CC_RUN_COMMAND="java -jar somefile.jar <options>"
```

### Environment injection

Clever Cloud can inject environment variables that are defined in the
dashboard and by add-ons linked to your application.

For Java applications, the environment is injected in the `System.getProperties()` object.

So, to use a variable, you just need `System.getProperties().getProperty("MY_VARIABLE")`.

For Groovy applications, just use the `System.getProperty("MY_VARIABLE")`.
{{% content "java-env-injection" %}}

## The Gradle Wrapper

Expand Down
11 changes: 1 addition & 10 deletions content/doc/applications/java/java-jar.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,7 @@ Example:
CC_RUN_COMMAND="java -jar somefile.jar <options>"
```

### Environment injection

Clever Cloud can inject environment variables that are defined in the
dashboard and by add-ons linked to your application.

For Java applications, the environment is injected in the `System.getProperties()` object.

So, to use a variable, you just need `System.getProperties().getProperty("MY_VARIABLE")`.

For Groovy applications, just use the `System.getProperty("MY_VARIABLE")`.
{{% content "java-env-injection" %}}

{{% content "deploy-git" %}}

Expand Down
2 changes: 2 additions & 0 deletions content/doc/applications/java/java-maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Example:
CC_RUN_COMMAND="java -jar somefile.jar <options>"
```

{{% content "java-env-injection" %}}

{{% content "new-relic" %}}

{{% content "deploy-git" %}}
Expand Down
2 changes: 2 additions & 0 deletions content/doc/applications/java/java-war.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Example:
CC_RUN_COMMAND="java -jar somefile.jar <options>"
```

{{% content "java-env-injection" %}}

{{% content "new-relic" %}}

{{% content "deploy-git" %}}
Expand Down
4 changes: 1 addition & 3 deletions content/doc/applications/scala/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ application.secret=${APPLICATION_SECRET}

{{% content "new-relic" %}}

{{% content "env-injection" %}}

To access environment variables from your code, just get them from the environment with `System.getenv("MY_VARIABLE")`. Be aware that it can return null.
{{% content "java-env-injection" %}}

{{% content "deploy-git" %}}

Expand Down
5 changes: 2 additions & 3 deletions content/doc/applications/scala/play-framework-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ For instance, if your Sbt project contains a `shared` and `play` module and you

{{% content "new-relic" %}}

{{% content "env-injection" %}}
{{% content "java-env-injection" %}}

To access the environment variables from your code, you need to add `my.option=${MY_VARIABLE}` in your `application.conf` file, and then use the configuration item `my.option` in your application. e.g `%clevercloud.db.url="jdbc:mysql://"${MYSQL_ADDON_HOST}"/"${MYSQL_ADDON_DB}`.
You can also use the `System.getenv("MY_VARIABLE")` method. Be aware that it can return null.
To access the environment variables from your code, you can also add `my.option=${MY_VARIABLE}` in your `application.conf` file, and then use the configuration item `my.option` in your application. e.g `%clevercloud.db.url="jdbc:mysql://"${MYSQL_ADDON_HOST}"/"${MYSQL_ADDON_DB}`.

{{% content "deploy-git" %}}

Expand Down
17 changes: 17 additions & 0 deletions shared/java-env-injection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Environment injection

Clever Cloud injects environment variables defined in the Console and by linked add-ons into your application. For JVM-based applications, all environment variables are passed as system properties using `-D` flags, making them accessible through `System.getProperty()`.

Check notice on line 3 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L3

[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.
Raw output
{"message": "[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 3, "column": 116}}}, "severity": "INFO"}

Check notice on line 3 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L3

[Google.Passive] In general, use active voice instead of passive voice ('are passed').
Raw output
{"message": "[Google.Passive] In general, use active voice instead of passive voice ('are passed').", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 3, "column": 166}}}, "severity": "INFO"}

To access a standard environment variable such as `MY_VARIABLE`, use `System.getProperty("MY_VARIABLE")` or `System.getenv("MY_VARIABLE")`.
Comment on lines +3 to +5

#### Variables with dots as JVM system properties

Check notice on line 7 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L7

[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.
Raw output
{"message": "[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 7, "column": 29}}}, "severity": "INFO"}

Environment variable names containing a dot (`.`) are handled differently. Since most shells do not support dots in variable names, these variables are passed exclusively as JVM system properties via `-D` flags, and are not set in the shell environment.

Check notice on line 9 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L9

[Google.Passive] In general, use active voice instead of passive voice ('are handled').
Raw output
{"message": "[Google.Passive] In general, use active voice instead of passive voice ('are handled').", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 9, "column": 51}}}, "severity": "INFO"}

Check notice on line 9 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L9

[Google.Contractions] Use 'don't' instead of 'do not'.
Raw output
{"message": "[Google.Contractions] Use 'don't' instead of 'do not'.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 9, "column": 94}}}, "severity": "INFO"}

Check notice on line 9 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L9

[Google.Passive] In general, use active voice instead of passive voice ('are passed').
Raw output
{"message": "[Google.Passive] In general, use active voice instead of passive voice ('are passed').", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 9, "column": 149}}}, "severity": "INFO"}

Check notice on line 9 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L9

[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.
Raw output
{"message": "[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 9, "column": 175}}}, "severity": "INFO"}

Check notice on line 9 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L9

[Google.Contractions] Use 'aren't' instead of 'are not'.
Raw output
{"message": "[Google.Contractions] Use 'aren't' instead of 'are not'.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 9, "column": 217}}}, "severity": "INFO"}

For example, if you define `my.app.config=production` in the Clever Cloud Console, the JVM receives `-Dmy.app.config=production` at startup. You can then retrieve it with:

Check notice on line 11 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L11

[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.
Raw output
{"message": "[Google.Acronyms] Spell out 'JVM', if it's unfamiliar to the audience.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 11, "column": 88}}}, "severity": "INFO"}

```java
String value = System.getProperty("my.app.config"); // returns "production"
```
Comment on lines +11 to +15

This is useful for setting framework-specific properties directly from the Console without modifying configuration files (e.g. Spring Boot properties, Quarkus settings, or any custom `-D` parameter your application expects).

Check failure on line 17 in shared/java-env-injection.md

View workflow job for this annotation

GitHub Actions / vale

[vale] shared/java-env-injection.md#L17

[Google.Latin] Use 'for example' instead of 'e.g.'.
Raw output
{"message": "[Google.Latin] Use 'for example' instead of 'e.g.'.", "location": {"path": "shared/java-env-injection.md", "range": {"start": {"line": 17, "column": 123}}}, "severity": "ERROR"}
Comment on lines +3 to +17
Loading