• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

IanDarwin/javasrc: Ian's Collected code examples from the O'Reilly Java ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

IanDarwin/javasrc

开源软件地址:

https://github.com/IanDarwin/javasrc

开源编程语言:

Java 86.4%

开源软件介绍:

JavaCook Source Files (javasrc)

This is my assorted collection of (you guessed it) Java source. It remains focused on building with Maven and Eclipse.

About a third of these files are featured in my O’Reilly Java Cookbook. I use a script (copyCodeSamples) to pre-format these for inclusion in the O’Reilly publishing toolchain; these will have // tag::foo[] and // end::foo[] comments to mark sections for mechanical inclusion into the book. These are just comments to Java tooling and can be completely ignored by people looking at the source code normally. Not all files with these comments necessarily appear in the book; files are included from the manuscript using asciidoctor's include mechanism and, when a code sample gets dropped from the book, I have no motivation to edit the tags out of the code, in case I use it elsewhere.

Structured as Maven Modules

This repo consists of about a dozen Maven modules (aka subdirectories :-)), as follows:

  • main - everything that isn’t in one of the others

  • desktop - GUI/Graphics, JavaFX, comm devices, etc.

  • ee - Jakarta EE (Java EE, J2EE) stuff

  • graal - Only works with graal vm

  • jlink - Not ready yet?

  • json - JSON parsing and formatting with various APIs

  • restdemo - REST

  • spark - Apache SPARK

  • unsafe - com.sun.Unsafe

  • testing - code that expands on testing (other modules have normal unit tests)

  • xml - XML parsing and formatting with various APIs

Prior to the Java Cookbook revision (late 2019/early 2020), this repo was one single module with no sub-modules. This became difficult to manage and to use, since, to compile anything, a user would have to wait for Maven to download all the dependencies and their dependencies and theirs…​ That revision seemed like a good time to split the whole shebang into smaller pieces. Each module has its own POM file, Maven structure, etc.

A main reason was that the CLASSPATH was becoming unmanageable. Not to mention MODULEPATH, and the time it takes to build the whole thing. Right now there is a lot of stuff in the "main" module, but this will get broken out into a few additional modules.

Now that it’s done this way, you can choose to just build one module or another, without having Maven download 3/4 of the Internet for dependencies. Just cd into one of the module directories and invoke mvn there. Or you can do them all by invoking mvn in the top-level directory. Useful mvn targets include compile and test. Do not use mvn package as the jar files won’t be useful on their own.

I broke it (but it’s easy to fix)

Unfortunately for those who already had the original all-in-one javasrc checked out and an Eclipse project created in that directory, you should do the following:

  • In Eclipse, delete javasrc project (do NOT check 'delete contents on disk'!);

  • Delete the old target folder (only): {rm -r or del/s} javasrc/target;

  • Do a "git pull" to rearrange the project and get the extra pom files;

  • Back in Eclipse, File->New Java Project->browse to (but not into) workspace/javasrc/main. Set project name to javasrc-main. If asked to upgrade the JDK release, say OK. If asked to create a module-info, click Do Not Create. Click OK/Finish.

  • You may want to create some or all of the other projects such as xml, jlink, spark, unsafe, …​ Do this same way as previous step: File→new Java project etc. Recommmended names are javasrc-xml, javasrc-unsafe, etc.

The older 'javasrcee' repository was originally formed by splitting it off from this repository, several years ago. Now, with this modularization, it has been merged back in, as the ee module.

No module-info

There are no module-info.java files in most of the subdirectories because this is not meant to be built and used as a library or even as a cohesive software base. A few that need them for imports &c have them.

Notes on Individual Modules

testing

Works under "mvn test". Compiles as an Eclipse project, but can’t run due to a Junit 5 loading conflict (pull requests welcome on this one, thanks).

Building

  • You MUST HAVE Java 11+ to successfully compile this whole package. Sorry if you are on some relic platform that doesn’t have Java 9 or later. Even OpenBSD has Java 17 (Thanks Kurt!). Also sorry if your organization is stuck on Java 8 due to application server issues.

  • I am using Eclipse for most of my development, and Maven for building, and Jenkins for automated building. Most Ant scripts have been removed; the few that remain will eventually be converted to Maven exec:java configurations.

  • Building with Eclipse tested with Eclipse 4.x; MUST HAVE "m2e" (free in the Eclipse Marketplace) Compiles and tests pass.

  • Building with Maven 3.x works and tests pass.

  • Building with other platforms? Good luck, but let me know if it works.

  • If you really need Java 8, try removing the module-info files. But you’re on your own. And you’ll need some exclusions for files that use newer language features.

Ian Darwin

Java Cookbook author




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
lxconan/java发布时间:2022-06-24
下一篇:
fantj2016/java-reader: 发布时间:2022-06-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap