Code Monkey home page Code Monkey logo

azurecloudmonk / javasrc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iandarwin/javasrc

0.0 2.0 0.0 48.95 MB

Ian's Collected code examples from the O'Reilly Java Cookbook & elsewhere

Home Page: http://javacook.darwinsys.com/

License: Other

HTML 10.46% Shell 0.24% Java 85.89% Python 0.05% PLpgSQL 0.01% C 2.28% Makefile 0.21% JavaScript 0.21% PostScript 0.05% Perl 0.12% Awk 0.04% C++ 0.13% XSLT 0.04% R 0.08% COBOL 0.03% C# 0.02% Fortran 0.01% CSS 0.09% Batchfile 0.04% Ruby 0.01%

javasrc's Introduction

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 11 (Thanks Kurt!). Also sorry if your organization is stuck on Java 8 due to application server issues. I am updating the Java Cookbook for Java 13+ and these files are the examples for that book.

  • 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

javasrc's People

Contributors

iandarwin avatar dependabot[bot] avatar cmawata avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.