question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

provide an Archetype for new PF4J based projects

See original GitHub issue

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 \
  -DartifactId=myapplication

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pinhead84commented, May 2, 2019

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). πŸ˜‰

0reactions
decebalscommented, May 17, 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@ \
  -DartifactId=@project_name@

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 \
  -DartifactId=myproject

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

myproject
β”œβ”€β”€ app
β”‚Β Β  β”œβ”€β”€ pom.xml
β”‚Β Β  └── src
β”‚Β Β      └── main
β”‚Β Β          β”œβ”€β”€ assembly
β”‚Β Β          β”‚Β Β  └── assembly.xml
β”‚Β Β          β”œβ”€β”€ java
β”‚Β Β          β”‚Β Β  └── com
β”‚Β Β          β”‚Β Β      └── mycompany
β”‚Β Β          β”‚Β Β          β”œβ”€β”€ Boot.java
β”‚Β Β          β”‚Β Β          β”œβ”€β”€ Greeting.java
β”‚Β Β          β”‚Β Β          └── WhazzupGreeting.java
β”‚Β Β          └── resources
β”‚Β Β              └── log4j.properties
β”œβ”€β”€ plugins
β”‚Β Β  β”œβ”€β”€ disabled.txt
β”‚Β Β  β”œβ”€β”€ enabled.txt
β”‚Β Β  β”œβ”€β”€ hello
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ plugin.properties
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pom.xml
β”‚Β Β  β”‚Β Β  └── src
β”‚Β Β  β”‚Β Β      └── main
β”‚Β Β  β”‚Β Β          └── java
β”‚Β Β  β”‚Β Β              └── com
β”‚Β Β  β”‚Β Β                  └── mycompany
β”‚Β Β  β”‚Β Β                      └── hello
β”‚Β Β  β”‚Β Β                          └── HelloPlugin.java
β”‚Β Β  β”œβ”€β”€ pom.xml
β”‚Β Β  └── welcome
β”‚Β Β      β”œβ”€β”€ plugin.properties
β”‚Β Β      β”œβ”€β”€ pom.xml
β”‚Β Β      └── src
β”‚Β Β          └── main
β”‚Β Β              └── java
β”‚Β Β                  └── com
β”‚Β Β                      └── mycompany
β”‚Β Β                          └── welcome
β”‚Β Β                              └── WelcomePlugin.java
β”œβ”€β”€ pom.xml
└── run.sh

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)
app/target/
-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 myproject-app-1.0-SNAPSHOT.zip
  • plugin jars (available in target directory of each plugin)
plugins/hello/target:
-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

plugins/welcome/target:
-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 run.sh that build and run your application. After you create the application, run this script and that is all. NOTE Before run run.sh script add execution permission with command chmod u+x run.sh.

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

dist
β”œβ”€β”€ 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quickstart - PF4J
The quickstart will set up a ready-to-use project in under a minute (depending on your ... artifactId and archetypeVersion (the latest PF4J version)....
Read more >
Maven Archetype – About
To create a new project based on an Archetype, you need to call mvn archetype:generate goal, like the following: mvn archetype:generate. PleaseΒ ...
Read more >
archetype-catalog.xml - Nexus Repository Manager
am.ik.archetype elm-spring-boot-blank-archetype 0.0.4-SNAPSHOT Blank multi ... velcro 1.0.0-SNAPSHOT This project provides a awesome Maven archetype forΒ ...
Read more >
Introducing the OSS Quickstart Archetype - Gunnar Morling
When bootstrapping new Maven-based projects, be it long-running ones, ... archetype is meant as a fresh alternative, not only providing moreΒ ...
Read more >
Plugin Project Configuration - Spinnaker
The easiest way to set up a new plugin project is to copy one of the ... "An example of a PF4J based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found