I’m somewhat surprised that there’s no response to this. All you that don’t use Eclipse out there must have a way to run/debug OH for testing what you’re doing, so I would expect some routine to exist already. Are everybody using the “demo app”, also those not using Eclipse?
I’ve come up with the following changes to make running a “full Karaf debug version” of OH less labor-intensive:
distributions/openhab/pom.xml | 44 +++++++++++++++++++++++++++++++++++++++++++
distributions/pom.xml | 26 +++++++++++++++++++------
pom.xml | 8 ++++++++
3 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/distributions/openhab/pom.xml b/distributions/openhab/pom.xml
index 62bdf6e..276e2f8 100644
--- a/distributions/openhab/pom.xml
+++ b/distributions/openhab/pom.xml
@@ -280,4 +280,48 @@
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>dev</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>delete-runtime</id>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ <phase>initialize</phase>
+ <configuration>
+ <excludeDefaultDirectories>true</excludeDefaultDirectories>
+ <filesets>
+ <fileset>
+ <directory>target/${project.artifactId}-${project.version}/runtime</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>archive</id>
+ <configuration>
+ <formats>
+ <format>dir</format>
+ </formats>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
diff --git a/distributions/pom.xml b/distributions/pom.xml
index 1ce55bc..fcf188b 100644
--- a/distributions/pom.xml
+++ b/distributions/pom.xml
@@ -15,11 +15,25 @@
<name>openHAB Distributions</name>
- <modules>
- <module>openhab-addons</module>
- <module>openhab-demo</module>
- <module>openhab</module>
- <module>openhab-verify</module>
- </modules>
+ <profiles>
+ <profile>
+ <id>dev</id>
+ <modules>
+ <module>openhab</module>
+ </modules>
+ </profile>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>openhab-addons</module>
+ <module>openhab-demo</module>
+ <module>openhab</module>
+ <module>openhab-verify</module>
+ </modules>
+ </profile>
+ </profiles>
</project>
diff --git a/pom.xml b/pom.xml
index 4c7c286..a9e7317 100644
--- a/pom.xml
+++ b/pom.xml
@@ -285,6 +285,14 @@
<pax.url.suffix/>
</properties>
</profile>
+ <profile>
+ <id>dev</id>
+ <properties>
+ <build.number>- development build -</build.number>
+ <online.repo>${oh.repo.releaseBaseUrl}/libs-snapshot</online.repo>
+ <pax.url.suffix>@snapshots</pax.url.suffix>
+ </properties>
+ </profile>
</profiles>
</project>
This creates a Maven dev
profile that, when used, tweaks the build of the “distro” quite a bit, making it both much faster and more convenient.
First, it makes sure that only the openhab
module is built, not openhab-addons
, openhab-demo
and openhab-verify
. This is where most of the time saving lies, particularly in skipping the add-ons I assume. It means that making “a new Karaf build” takes only 30–40 seconds, assuming that the artifacts that you want to use are already installed in your local Maven repo. Those that aren’t found in your local Maven repo will be downloaded from “the latest jfrog snapshot”, so to use your own code, make sure to install them (`mvn clean build -pl :) from the repositories where they live first.
The second thing it does is to alter the assembly, so that instead of producing .zip
and .tar.gz
archives, a folder is generated under openhab-distro/distributions/openhab/target
. The folder will be called whatever the version you’re building is, e.g. openhab-5.0.0-SNAPSHOT
. In this folder, there’s a full Karaf “installation” of OH, that can be run directly from there. No moving/copying and extraction of files are required.
Since I haven’t gotten an answer to OSGi framework lifecycle, I have peeked at what the upgrade script does, and it seems to be merely to delete the whole runtime
folder. This is necessary to prevent old versions of the bundles to be used when starting Karaf, since they are cached. So, the dev
Maven build also deletes the runtime
folder, so that when you start Karaf, it will always use the latest versions of the bundles. But, crucially, the rest of the system configuration remains intact, so you don’t have to create a user and configure stuff for each build.
So, to wrap it up, all I do is (from the openhab-distro
repo):
mvn package -Pdev
When that’s completed, the folder is created and ready to run. Please note that I don’t use clean
, as that would erase the whole target
folder and the configuration of this “OH installation” with it. I also use package
because there’s no point in trying to “install” this in the local Maven repo - and it would also fail because a folder isn’t supported for installation (it has to be some kind of archive).
Then, from openhab-distro/distributions/openhab/target/openhab-5.0.0-SNAPSHOT
(or what corresponds to the version you’re building) I simply run:
.\start_debug
…and OH starts with port 5005 available for debugging. I can then attach Eclipse’s debugger, and I assume and other compatible debugger, to localhost:5005
and work with breakpoints, watch etc.
If there is any interest in making this available to others, I could create a PR for “distro”…? All my changes only apply if one activates the dev
profile, so it should have no implications for any existing routines/automated builds that exist.