Project dependencies and Maven
-
Automated third-party class import and dependency management
-
Executing automated tests
-
Complete project lifecycle:
compile, test, execute, package, deploy
-
Extensible plugin architecture
Source: CreatePdf.java |
PDF output |
import com.itextpdf.kernel.pdf.PdfDocument; ... final PdfWriter writer = new PdfWriter("helloWorld.pdf"); final PdfDocument pdf = new PdfDocument(writer); final Document document = new Document(pdf, PageSize.A8.rotate()); document.add(new Paragraph("Hello World!"). setFontColor(ColorConstants.MAGENTA). setFontSize(20)); document.close(); |
|
|
mvn dependency:tree
...
--- dependency:3.6.1:tree (default-cli) @ hellopdf ---
de.hdm_stuttgart.mi:hellopdf:jar:0.9
\- com.itextpdf:itext-core:pom:8.0.2:compile
+- com.itextpdf:barcodes:jar:8.0.2:compile
| \- org.slf4j:slf4j-api:jar:1.7.36:compile
+- com.itextpdf:font-asian:jar:8.0.2:compile
+- com.itextpdf:forms:jar:8.0.2:compile
+- com.itextpdf:hyph:jar:8.0.2:compile
+- com.itextpdf:io:jar:8.0.2:compile
| \- com.itextpdf:commons:jar:8.0.2:compile
+- com.itextpdf:kernel:jar:8.0.2:compile ...
- CDN
- Company local
No. 108
Dealing with IBAN numbers
Q: |
The java-iban
framework provides methods for dealing with IBAN
numbers. Create a new mi-maven-helloworld
archetype based project. Add a Code and execute the following tasks:
NoteSee Java-IBAN for code examples. |
||||
A: |
|
mvn archetype:generate [INFO] Scanning for projects... ... 1: remote -> am.ik.archetype:elm-spring-boot-blank-archetype ... 2: remote -> am.ik.archetype:graalvm-blank-archetype ... 3: remote -> am.ik.archetype:graalvm-springmvc-blank-archetype ... ... 2083: remote -> org.apache.maven.archetypes:maven-archetype-quickstart... ... 3330: remote -> za.co.absa.hyperdrive:component-archetype_2.12 (-) Choose a number or apply filter ... |
Helper.java |
pom.xml |
---|---|
|
|
goik@goiki Helper> mvn install [INFO] Scanning for projects... [INFO] ------------------------------------------- [INFO] Building helper 0.9 ... [INFO] Installing .../Helper/target/helper-0.9.jar to /ma/goik/.m2/repository/mi/calc/common/1.0/common-1.0.jar
goik@goiki tmp> unzip ...hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0.9.jar
Archive: .../.m2/repository/.../sd1/helper/0.9/helper-0.9.jar
creating: META-INF/
inflating: META-INF/MANIFEST.MF
creating: de/
creating: de/hdm_stuttgart/
creating: de/hdm_stuttgart/mi/
creating: de/hdm_stuttgart/mi/sd1/
inflating: de/hdm_stuttgart/mi/sd1/Helper.class
creating: META-INF/maven/
creating: META-INF/maven/de.hdm_stuttgart.mi.sd1/
creating: META-INF/maven/de.hdm_stuttgart.mi.sd1/helper/
inflating: META-INF/maven/de.hdm_stuttgart.mi.sd1/helper/pom.xml
inflating: META-INF/maven/de.hdm_stuttgart.mi.sd1/helper/pom.properties
<project ...> ... <groupId>de.hdm_stuttgart.mi.sd1</groupId> <artifactId>lottery</artifactId> <version>0.9</version> <packaging>jar</packaging> <name>lottery</name> <dependencies> <dependency> <groupId>de.hdm_stuttgart.mi.sd1</groupId> <artifactId>helper</artifactId> <version>0.9</version> </dependency> ... </project>
static public long binomial(int n, int k) { return (Helper.factorial(n) / Helper.factorial(k) / Helper.factorial(n - k)); } public static void main(String[] args) { System.out.println("There are " + binomial(5, 2) + " ways to draw 2 out of 5 numbers"); System.out.println("There are " + binomial(49, 6) + " ways to draw 6 out of 49 numbers"); }
No. 109
Cancelling fractions
When cancelling a fraction its greatest common divisor of denominator an nominator is being required. In the example of 12/18 this value is 6 allowing to cancel this fraction to 1/3.
Thus a project dealing with fractions may requires the import of
your previous Finding the greatest common divisor of two integer
values exercise. In this exercise
you will solely work on your local
~/.m2/repositories
drive:
-
In your GCD exercise project create a local file system Maven export by executing “mvn
install
” . Alternatively you may hitRun
-->Edit Configurations
of your Idea IDE for defining a corresponding Maven runtime configuration by enteringinstall
in the »Command line« field. -
Defining Finding the greatest common divisor of two integer values as said dependency ❶ in your fraction related project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.hdm-stuttgart.de.sd1</groupId> <artifactId>fraction</artifactId> <version>1.0</version> <packaging>jar</packaging> <name>fraction</name> ... <dependencies> <dependency> ❶ <groupId>de.hdm-stuttgart.de.sd1</groupId> <artifactId>gcd</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>junit</groupId> ... </dependency> </dependencies> </project>
Q: |
We have already implemented GCD
computation in Finding the greatest common divisor of two integer
values . The current
exercise's idea is about implementing the operation of cancelling
of fractions by using the method
Test your results. |
A: |
Modifying the constructor is straightforward: On creating a fraction we simply divide both numerator and denominator by the GCD value:
Its tempting to implement
This is however too shortsighted. Consider the example
. Our simple implementation proposal would call
We may instead transform the term in question by exchanging
the numerators like
to enable cancelling prior to multiplying. Now the call
Similar reflections lead to the clue decomposing the
denominators when implementing
See complete implementation here. We may re-use out test:
|
No. 110
Dealing with local Maven dependencies
Q: |
This exercise is actually a preparation for ongoing exercises relying on importing local Maven artifacts. Follow this section's description and create two projects A and B. Project B shall import some implementation from project A as being previously described. If you lack an idea you may just use the given Lottery project using the Helper project. |