Skip to content
Snippets Groups Projects
Commit 172862f7 authored by Emmanuel Bruno's avatar Emmanuel Bruno
Browse files

adds a first draft.

parent a4049270
No related branches found
No related tags found
No related merge requests found
.ipynb_checkpoints
_config.yml
_build
_toc.yml
%% Cell type:markdown id:3cd4997c-1ed7-4fdc-bf4c-aaea4dceb215 tags:
# Quickstart Java notebook
%% Cell type:markdown id:d9166747-a475-463a-8120-3013056691bf tags:
## Java Code
%% Cell type:code id:395c3ff1-1c66-4457-b7f5-2b096d51c3d1 tags:
``` java
%%shell
mvn --version
```
%% Output
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /home/jovyan/.sdkman/candidates/maven/current
Java version: 17.0.6, vendor: Eclipse Adoptium, runtime: /home/jovyan/.sdkman/candidates/java/17.0.6-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.82-0-virt", arch: "aarch64", family: "unix"
%% Cell type:markdown id:7574b173-b657-40d1-b884-cd542984334a tags:
### Between code cells
%% Cell type:code id:6eb1582a-7137-49dc-850a-c32d2ccec50b tags:
``` java
List<String> fruits=List.of("Banana","Apple","Orange");
```
%% Cell type:code id:07b6fd43-3ad6-4405-b0d8-70365b33cf7f tags:
``` java
fruits
.stream()
.sorted()
.map(String::toLowerCase)
.forEach(System.out::println);
```
%% Output
apple
banana
orange
%% Cell type:code id:400a1d1c-91db-4b46-9e3d-ce2e686ab3ad tags:
``` java
public class Pair<E,F> {
private E e;
private F f;
public Pair(E e,F f) {
this.e = e;
this.f = f;
}
public String toString() {
return "(%s,%s)".formatted(e.toString(),f.toString());
}
}
```
%% Cell type:code id:ca418a9e-196d-4499-bfe4-19f448817c89 tags:
``` java
Pair<String, Integer> p= new Pair<>("A",10);
p;
```
%% Output
(A,10)
%% Cell type:markdown id:abe49b7c-4fb7-4f0c-b570-1fc1fe0f2dc4 tags:
### External compilation
#### From cells
This image support external compilation to allow annotation processors (like lombok, JPA, JAX-RS, ...).
```{warning}
The compiled class cannot be changed until the kernel is restarted.
```
%% Cell type:code id:6fac3be4-b89e-46e6-9f25-5bd643cc8823 tags:
``` java
%%compile fr/univtln/bruno/Vehicule.java
package fr.univtln.bruno;
import lombok.experimental.FieldDefaults;
import lombok.*;
import lombok.experimental.*;
import java.time.LocalDate;
import java.util.*;
@FieldDefaults(level=AccessLevel.PRIVATE)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
@EqualsAndHashCode(of= {"numeroMoteur","numeroChassis"})
@ToString(of= {"numeroMoteur","numeroChassis","numeroImmatriculation"})
public class Vehicule
{
String numeroMoteur;
String numeroChassis;
String numeroImmatriculation;
LocalDate dateMiseEnCirculation;
@Singular
List<String> interventions;
}
```
%% Cell type:code id:19298648-64e3-48a4-ae50-cd3e705f1e15 tags:
``` java
import fr.univtln.bruno.Vehicule;
Vehicule v = Vehicule.builder().numeroMoteur("A12").build();
```
%% Cell type:code id:1bc26bcc-9506-4be1-a9c6-1a4ae0301187 tags:
``` java
v;
```
%% Output
Vehicule(numeroMoteur=A12, numeroChassis=null, numeroImmatriculation=null)
%% Cell type:markdown id:ed8f4640-ac2a-4ba3-a7ee-d86c69b62cd5 tags:
#### From Maven
%% Cell type:code id:a7a5b560-b3e0-47f7-bb3b-e46dc18ff488 tags:
``` java
%%shell
cd /home/jovyan/work
[[ ! -f MyApp ]] && \
mvn archetype:generate --ntp --batch-mode \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4 \
-DgroupId=fr.univtln.mylogin \
-DartifactId=MyApp \
-Dversion=1.0-SNAPSHOT
( cd Myapp && mvn --ntp --batch-mode package )
```
%% Output
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> archetype:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< archetype:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- archetype:3.2.1:generate (default-cli) @ standalone-pom ---
[WARNING] Parameter 'localRepository' is deprecated core expression; Avoid use of ArtifactRepository type. If you need access to local repository, switch to '${repositorySystemSession}' expression and get LRM from it instead.
[INFO] Generating project in Batch mode
[INFO] Archetype repository not defined. Using the one from [org.apache.maven.archetypes:maven-archetype-quickstart:1.4] found in catalog remote
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: fr.univtln.mylogin
[INFO] Parameter: artifactId, Value: MyApp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: fr.univtln.mylogin
[INFO] Parameter: packageInPathFormat, Value: fr/univtln/mylogin
[INFO] Parameter: package, Value: fr.univtln.mylogin
[INFO] Parameter: groupId, Value: fr.univtln.mylogin
[INFO] Parameter: artifactId, Value: MyApp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.849 s
[INFO] Finished at: 2023-03-29T16:50:30Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate (default-cli) on project standalone-pom: A Maven project already exists in the directory /home/jovyan/work/MyApp -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< fr.univtln.mylogin:MyApp >----------------------
[INFO] Building MyApp 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.0.2:resources (default-resources) @ MyApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jovyan/work/Myapp/src/main/resources
[INFO]
[INFO] --- compiler:3.8.0:compile (default-compile) @ MyApp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.0.2:testResources (default-testResources) @ MyApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jovyan/work/Myapp/src/test/resources
[INFO]
[INFO] --- compiler:3.8.0:testCompile (default-testCompile) @ MyApp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- surefire:2.22.1:test (default-test) @ MyApp ---
[WARNING] Parameter 'localRepository' is deprecated core expression; Avoid use of ArtifactRepository type. If you need access to local repository, switch to '${repositorySystemSession}' expression and get LRM from it instead.
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running fr.univtln.mylogin.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.101 s - in fr.univtln.mylogin.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.0.2:jar (default-jar) @ MyApp ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.919 s
[INFO] Finished at: 2023-03-29T16:50:35Z
[INFO] ------------------------------------------------------------------------
%% Cell type:markdown id:f718e40e-51c0-4b9f-a895-d70d7b19a0c4 tags:
## IDE
VSCode is supported from the launcher or via link : [/home/jovyan/work/MyApp](/code-server/?folder=/home/jovyan/work/MyApp)
%% Cell type:markdown id:c945c5c4-79c4-401d-88ff-71e86c60f0be tags:
## UML
%% Cell type:code id:9ce0a18e-557a-4200-894a-c177ce4a353e tags:
``` java
%%plantUML
@startuml
class A {
- id: int
- value: String
--
+ action(): void
}
class B {
}
A<|--B
@enduml
```
%% Output
%% Cell type:markdown id:d31766a4-3532-4aaf-a169-359a21efebf2 tags:
## Source code
%% Cell type:code id:b6663cc2-b90d-4090-95fd-5c9c033e03aa tags:
``` java
%%javasrcClassByName Voiture
Voiture.java
```
%% Output
```Java
public class Voiture {
private long id;
private String name;
public void start() {
System.out.println("Vroum.");
}
@Deprecated
public void old() {
}
}
```
%% Cell type:code id:3cc86737-d6b6-4cb2-8f27-b90ae09594ef tags:
``` java
%%javasrcMethodByName Voiture start
Voiture.java
```
%% Output
```Java
public void start() {
System.out.println("Vroum.");
}
```
%% Cell type:code id:0e44b6d5-13c8-4d09-bc20-f0034ef0d516 tags:
``` java
%%javasrcMethodByAnnotationName Voiture Deprecated
Voiture.java
```
%% Output
```Java
@Deprecated
public void old() {
}
```
%% Cell type:markdown id:019e262f-1b3b-41a8-8c08-90f968b2bbab tags:
## Shell
%% Cell type:code id:1a286e60-5b12-4e3d-8d83-5effdb557e53 tags:
``` java
%%shell
uname -a
```
%% Output
Linux 330851cf59b4 5.15.82-0-virt #1-Alpine SMP Mon, 12 Dec 2022 09:15:17 +0000 aarch64 aarch64 aarch64 GNU/Linux
%% Cell type:code id:4b94d8f6-2ab5-4536-806c-24d98a24078b tags:
``` java
```
public class Voiture {
private long id;
private String name;
public void start() {
System.out.println("Vroum.");
}
@Deprecated
public void old() { }
}
\ No newline at end of file
docker run --rm \
--user root \
--name notebook-java-${PWD##*/} \
--volume $PWD:/home/jovyan/notebooks \
--volume $HOME/JUPYTER_WORK:/home/jovyan/work \
--publish 8888:8888 \
--env NB_UID=$UID \
brunoe/jupyter-java-base:develop start-notebook.sh --notebook-dir=/home/jovyan/notebooks
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment