Tinny Java Excersise, Experimental, Practices Programms.
- OpenJDK >= 11
- Eclipse >= 201903 (v4.10), "Eclipse IDE for Java EE Developers" package
- or Spring Tools 4 (STS4 >= 4.2.1)
- Maven >= 3.6.1 (download automatically by mvnw script. also works by 3.x)
- use UTF-8 for source code and other text files.
to setup Eclipse/STS4, see setup-type2
in https://github.com/msakamoto-sf/howto-eclipse-setup and follow:
- Eclipse install how-to
- Clean Up/Formatter configuration
- Recommended plugin:
import checkstyle configuration xml into eclipse:
- import xml into eclipse global configuration.
- Window -> Preferences -> Checkstyle -> Global Check Configurations : click "New"
- Select: "Project Relative Configuration"
- Location: click "Browse" -> then select project -> select
javasnack/checkstyle-settings/google_checks-8.28_custom.xml
- Name: set proper name
- Apply and Close
- setup project specific setting
- right-click project -> Properties (ALT + Enter)
- Checkstyle -> check "Checkstyle active for this project"
- select imported xml configration
- Apply and Close
- run first checkstyle
- right-click project -> Checkstyle -> "Check Code with Checkstyle"
reload updated xml to Eclipse/STS: (unstable way)
- some operations in Window -> Preferences -> Checkstyle config then "Apply and Click". (e.g. checkbox on <> off)
- project setting -> switch checkstyle activate / deactivate some times.
- rebuild project.
- import project specific include/exclude filter.
- right-click project -> Properties -> SpotBugs -> check "Enable project specific settings"
- at filter file tab, add "spotbugs-exclude-filter.xml" to exclude filter file, add "spotbugs-include-filter.xml" to include filter file.
- SpotBugs plugin setting (see pom.xml configuration)
- set effort (分析力) to "Default"
- set max rank (報告する最小ランク) to 15
- set threshold (レポートする最低の信頼度) to "Medium"
- check below categories (see spotbugs-include-filter.xml)
- "Bad practice"
- "Malicious code vulnerability"
- "Correctness"
- "Performance"
- "Security"
- "Dodgy code"
- "Multithreaded correctness"
- "Internationalization"
- do NOT check "Experimental" category.
- run SpotBugs check manually:
- right-click project -> SpotBugs -> click "Find Bugs"
If you edited exclude/include xml filter, then right-click project -> SpotBugs -> clear markers and Find Bugs again.
SpotBugs reference:
- https://spotbugs.github.io/
- https://spotbugs.github.io/spotbugs-maven-plugin/
- https://spotbugs.readthedocs.io/en/latest/
- https://spotbugs.readthedocs.io/ja/latest/
- import project specific ruleset xml.
- right-click project -> Properties -> PMD -> check "Enable PMD"
- "Rule source" -> check "Use the ruleset configured in a project file" -> Browse -> select
javasnack-custom-pmd-rule.xml
- if you asked "The project doesn't contain a ruleset file. Do you want to create a ruleset from the configured properties ?", click "No".
If you edited rule xml, no need to reconfigure. just do PMD -> "Check Code" again.
PMD reference:
- https://pmd.github.io/
- https://pmd.github.io/latest/
- https://pmd.github.io/latest/pmd_userdocs_tools_maven.html
- https://maven.apache.org/plugins/maven-pmd-plugin/index.html
- https://github.com/pmd/pmd-eclipse-plugin
javasnack demonstrates classloading from jar in resources and referencing project related local repository.
- build jar library and install to src/main/resources/.
- build jar library and deploy to project related path. (NOT to
~/.m2/repository/
) - setup
~/.m2/settings.xml
to refer project related path. - build main project.
(You can skip this step : already pre-built jar has been commited to src/main/resources/JCLDemo/)
build myapi-impl(1|2).jar, "GreetingInterface" implementation:
$ cd javasnack/
$ pushd subprojects/myapi-impl1
$ javac src/myapi/*.java
$ jar cvf myapi-impl1.jar -C src .
$ cp myapi-impl1.jar ../../src/main/resources/JCLDemo/
$ popd
$ pushd subprojects/myapi-impl2
$ javac src/myapi/*.java
$ jar cvf myapi-impl2.jar -C src .
$ cp myapi-impl2.jar ../../src/main/resources/JCLDemo/
$ popd
These jar files are used for demonstration of https://github.com/kamranzafar/JCL at JCLDemo, TestJCLDemoApis.
(You can skip this step : already pre-built jar has been commited to repo/subprojects/)
build testjar1-1.0.jar:
$ cd javasnack/subprojects/jar1
$ javac src/testjar1/*.java
$ jar cvfm testjar1-1.0.jar manifest.mf -C src/ testjar1/Greeting.class
$ java -jar testjar1-1.0.jar
Grood Morning, ABC.
Good Afternoon, DEF.
install jar to project local repository:
$ cd javasnack/
$ ./mvnw install:install-file \
-DlocalRepositoryPath=subprojects/repo \
-DcreateChecksum=true \
-Dpackaging=jar \
-Dfile=subprojects/jar1/testjar1-1.0.jar \
-DgroupId=subprojects \
-DartifactId=testjar1 \
-Dversion=1.0
This jar file are used for demonstration of pom.xml local repository usage at pom.xml and LocalJarDemo.
see:
- java - Can I add jars to maven 2 build classpath without installing them? - Stack Overflow
- Mavenプロジェクトで3rdパーティJARを扱う方法|Ouobpo
This maven project includes demonstrating maven local file repository.
Check your $HOME/.m2/setting.xml
and if <mirror>
- <mirrorOf>
setting is *
, then fix it to external:*
.
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://your.mirroring.repository/nexus/content/groups/public/</url>
</mirror>
</mirrors>
to:
...
<mirrorOf>external:*</mirrorOf>
...
If <mirrorOf>
is *
, then maven searches all dependencies to <url>
repository, so, local file dependencies couldn't be resolved.
About <mirrorOf>
setting, see :
- http://maven.apache.org/guides/mini/guide-mirror-settings.html
- http://stackoverflow.com/questions/17019308/maven-setup-another-repository-for-certain-dependency
$ cd javasnack/
$ ./mvnw package
if you want to skip test running, but compile test code:
$ ./mvnw -DskipTests package
if you want to skip test compile and running either:
$ ./mvnw -Dmaven.test.skip=true package
$ java -jar target/javasnack-(version).jar
or
$ ./mvnw exec:java
surefire test only (excluding @Tag("junit5-tag-filter-2")
and @MyJUnit5MetaAnnotation2
annotated test cases):
$ ./mvnw test
NOTE: some thread feature test cases may be fail cause of timing sensitivity.
all test cases (surefire + failsafe : including @Tag("junit5-tag-filter-2")
and @MyJUnit5MetaAnnotation2
annotated test cases):
$ ./mvnw integration-test
run checkstyle from command line:
$ ./mvnw checkstyle:check
run SpotBugs from command line:
$ ./mvnw spotbugs:check
run PMD from command line:
$ ./mvnw pmd:pmd
generate report:
$ ./mvnw site
all:
$ ./mvnw clean integration-test site
jdk11:
JDK 11 Documentation - Home
JDK 11ドキュメント - ホーム
- API JavaDoc(en)
- API JavaDoc(ja)
javadoc:
Javadoc ドキュメンテーションコメントの書き方 - Qiita
Javadocメモ(Hishidama's Javadoc Memo)
Javadocの記述