forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eugenp#6588 from macroscopic64/master
[BAEL-2073] Java 9 Migration Issues and Resolution
- Loading branch information
Showing
6 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
<artifactId>core-java-modules</artifactId> | ||
<name>core-java-modules</name> | ||
<packaging>pom</packaging> | ||
|
||
<parent> | ||
<artifactId>parent-modules</artifactId> | ||
<groupId>com.baeldung</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modules> | ||
<module>pre-jpms</module> | ||
</modules> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<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> | ||
<artifactId>pre-jpms</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>pre-jpms</name> | ||
|
||
<parent> | ||
<artifactId>parent-modules</artifactId> | ||
<groupId>com.baeldung</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../../</relativePath> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.25</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>pre-jpms</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>3.1.1</version> | ||
<executions> | ||
<execution> | ||
<id>copy-dependencies</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory> | ||
${project.build.directory}/dependency-jars/ | ||
</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.baeldung.prejpms.App</mainClass> | ||
<addClasspath>true</addClasspath> | ||
<classpathPrefix>dependency-jars/</classpathPrefix> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
77 changes: 77 additions & 0 deletions
77
core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.baeldung.prejpms; | ||
|
||
import java.io.StringWriter; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.Marshaller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.sun.crypto.provider.SunJCE; | ||
|
||
import sun.misc.BASE64Encoder; | ||
import sun.reflect.Reflection; | ||
|
||
public class App { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
getCrytpographyProviderName(); | ||
getCallStackClassNames(); | ||
getXmlFromObject(new Book(100, "Java Modules Architecture")); | ||
getBase64EncodedString("Java"); | ||
} | ||
|
||
private static void getCrytpographyProviderName() { | ||
try { | ||
LOGGER.info("1. JCE Provider Name: {}\n", new SunJCE().getName()); | ||
} catch (Throwable e) { | ||
LOGGER.error(e.toString()); | ||
} | ||
} | ||
|
||
private static void getCallStackClassNames() { | ||
try { | ||
StringBuffer sbStack = new StringBuffer(); | ||
int i = 0; | ||
Class<?> caller = Reflection.getCallerClass(i++); | ||
do { | ||
sbStack.append(i + ".") | ||
.append(caller.getName()) | ||
.append("\n"); | ||
caller = Reflection.getCallerClass(i++); | ||
} while (caller != null); | ||
LOGGER.info("2. Call Stack:\n{}", sbStack); | ||
} catch (Throwable e) { | ||
LOGGER.error(e.toString()); | ||
} | ||
} | ||
|
||
private static void getXmlFromObject(Book book) { | ||
try { | ||
Marshaller marshallerObj = JAXBContext.newInstance(Book.class) | ||
.createMarshaller(); | ||
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); | ||
|
||
StringWriter sw = new StringWriter(); | ||
marshallerObj.marshal(book, sw); | ||
LOGGER.info("3. Xml for Book object:\n{}", sw); | ||
} catch (Throwable e) { | ||
LOGGER.error(e.toString()); | ||
} | ||
|
||
} | ||
|
||
private static void getBase64EncodedString(String inputString) { | ||
try { | ||
String encodedString = new BASE64Encoder().encode(inputString.getBytes()); | ||
LOGGER.info("4. Base Encoded String: {}", encodedString); | ||
} catch (Throwable e) { | ||
LOGGER.error(e.toString()); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.baeldung.prejpms; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "book") | ||
public class Book { | ||
private long id; | ||
private String name; | ||
|
||
public Book() { | ||
} | ||
|
||
public Book(long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
@XmlAttribute | ||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@XmlElement(name = "title") | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>[%level] %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="debug"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters