Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide an Archetype for new PF4J based projects #306

pinhead84 opened this issue Mar 25, 2019 · 5 comments

provide an Archetype for new PF4J based projects #306

pinhead84 opened this issue Mar 25, 2019 · 5 comments


Copy link

To make using PF4J for new developers as easy as possible, we might consider providing a Maven Archetype. A developer might just enter a command like

mvn archetype:generate \
  -DarchetypeGroupId=org.pf4j \
  -DarchetypeArtifactId=pf4j-application \
  -DarchetypeVersion=3.0.0 \
  -DgroupId=com.mycompany \

and automatically a basic Maven project structure is created, from which he can start the development of his new PF4J based application. The created project might use the same (or similar) files, that are used in the demo application (see #304).

I've never created those Archetypes yet, but according to the documentation it looks quite simple to me. What do you think about this?

Copy link

A Quickstart Archetype is welcome in my opinion. In this mode you have a functional demo application without being forced to refactorize (change the root package name, application name, ...).
I implemented this feature in other popular project initiated by me (Pippo). Fore more details see:

Copy link
Contributor Author

In the next few days I'll try to create such an Archetype for PF4J. You'll receive a pull request for the pf4j_3 branch as soon as I got something usable to show. ;)

@decebals decebals added this to the PF4J 3 milestone Apr 16, 2019
Copy link

decebals commented May 2, 2019

Have you already started working on this feature?
If not, I'd like to try. This feature is the last one on PF4J 3 milestone.

Copy link
Contributor Author

Due to a lot of work I did not had the the time to start this feature yet. I guess I would need about one or two more weeks. If you don't want to wait for so long, feel free to create the archetype by yourself.

Maybe it's even better, because you're using a different structure for your projects / plugins (e.g. using the development classpath). ;)

decebals added a commit that referenced this issue May 16, 2019
Copy link

decebals commented May 16, 2019

Finally, we have support for Maven Archetype.
The archetypes are available in maven-archetypes directory. For the moment is available only quickstart.

To create a new basic PF4J application you call the quickstart archetype with a command like:

mvn -archetype:generate \
  -DarchetypeGroupId=org.pf4j \
  -DarchetypeArtifactId=pf4j-quickstart \
  -DarchetypeVersion= @pf4j.version@ \
  -DgroupId=@packet.root@ \

Please replace holders (@*@) with what you want.

For example, if I want to create a quickstart PF4J application with name myproject, with the root package com.mycompany using PF4J version 3.0.0-SNAPSHOT I will execute the command:

mvn -archetype:generate \
  -DarchetypeGroupId=org.pf4j \
  -DarchetypeArtifactId=pf4j-quickstart \
  -DarchetypeVersion=3.0.0-SNAPSHOT \
  -DgroupId=com.mycompany \

After the command is executed, your PF4J application is available in myprojectdirectory.
The structure of myproject directory is:

├── app
│   ├── pom.xml
│   └── src
│       └── main
│           ├── assembly
│           │   └── assembly.xml
│           ├── java
│           │   └── com
│           │       └── mycompany
│           │           ├──
│           │           ├──
│           │           └──
│           └── resources
│               └──
├── plugins
│   ├── disabled.txt
│   ├── enabled.txt
│   ├── hello
│   │   ├──
│   │   ├── pom.xml
│   │   └── src
│   │       └── main
│   │           └── java
│   │               └── com
│   │                   └── mycompany
│   │                       └── hello
│   │                           └──
│   ├── pom.xml
│   └── welcome
│       ├──
│       ├── pom.xml
│       └── src
│           └── main
│               └── java
│                   └── com
│                       └── mycompany
│                           └── welcome
│                               └──
├── pom.xml

The quickstart archetype is based on the demo project with some modifications:

  • the api module was removed for simplicity and the content of this module (the Greeting extension point) was merged in the app module

The first step after you create a new PF4J application via quickstart archetype is to create the artifacts using mvn clean package. The result of this command is:

  • application jar/zip (available in target directory of app)
-rw-r--r-- 1 decebal decebal   5525 mai 16 22:01 myproject-app-1.0-SNAPSHOT.jar
-rw-r--r-- 1 decebal decebal 872934 mai 16 22:01
  • plugin jars (available in target directory of each plugin)
-rw-r--r-- 1 decebal decebal 3399 mai 16 22:01 hello-plugin-1.0-SNAPSHOT-all.jar
-rw-r--r-- 1 decebal decebal 3193 mai 16 22:01 hello-plugin-1.0-SNAPSHOT.jar

-rw-r--r-- 1 decebal decebal 289149 mai 16 22:01 welcome-plugin-1.0-SNAPSHOT-all.jar
-rw-r--r-- 1 decebal decebal   3451 mai 16 22:01 welcome-plugin-1.0-SNAPSHOT.jar

The plugins are released in JAR format (as fat/uber jars => include dependencies).
The application jar contain in manifest the main class and the classpath.

For Linux (I use Linux), I supplied out of the box a very tiny script that build and run your application. After you create the application, run this script and that is all.
NOTE Before run script add execution permission with command chmod u+x

The creates a very simple and clean structure for you application, structure availables in a new dist (from distribution) directory:

├── lib
│   ├── commons-lang-2.4.jar
│   ├── java-semver-0.9.0.jar
│   ├── log4j-1.2.16.jar
│   ├── pf4j-3.0.0-SNAPSHOT.jar
│   ├── slf4j-api-1.7.25.jar
│   └── slf4j-log4j12-1.7.7.jar
├── myproject-app-1.0-SNAPSHOT.jar
└── plugins
    ├── disabled.txt
    ├── enabled.txt
    ├── hello-plugin-1.0-SNAPSHOT-all.jar
    └── welcome-plugin-1.0-SNAPSHOT-all.jar

Now, it's very easy to run your application (with plugins), follow the below steps:

  • go to dist directory (cd dist)
  • run your application (java -jar *.jar or more explicitly java -jar myproject-app-1.0-SNAPSHOT.jar or double click on the jar file).

If you need to distribute your application then zip the dist directory and send the zip file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants