I am trying to deploy the simplest application on Cloudbees, using the Spark Java framework. This produces a Jar file that I tried to deploy through the Jenkins push->deploy, but it warns me that the deploy plugin cannot deploy a jar file...
Whatever, I deployed my jar through the CloudBees SDK and the CLI :
bees app:deploy -t java -R java_version=1.7 target\myapp-with-dependencies.jar
And then it tells me that the application has been deployed to my URL. But when I try to reach this URL, I get a 502 Bad Gateway Error...
However, whether if run my main class through IntelliJ or with the Jar file produced by maven, the URL 127.0.0.1:8080 returns me the expected Hello Spark.
Here is my main class :
public class HelloSpark {
public static void main(String[] args) {
String port = System.getProperty("app.port","8080");
//So that the port is the one used by CloudBees
Spark.setPort(Integer.parseInt(port));
Spark.get(new Route("/") {
#Override
public Object handle(Request request, Response response) {
return "Hello Spark";
}
});
}
}
And here is my pom file :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spark-from-scratch</groupId>
<artifactId>spark-from-scratch</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>spark</groupId>
<artifactId>spark</artifactId>
<version>0.9.9.4-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>HelloSpark</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I think you need to specify your main class in this way:
bees app:deploy -t java -R class=your.main.Class -R java_version=1.7 PATH_TO_APP_PACKAGE
I think it's necessary to specify it in your command, you can read more here:
https://developer.cloudbees.com/bin/view/RUN/Java+Container
Related
For some reason when I clean and build my maven project in NetBeans, the resulting jar file does not execute when clicked. I've tried altering the pom file several times, here is what it looks like now:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>mainWindow.java</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>corp1</id>
<name>Corporate Repository</name>
<url>file:///EGR-1L11QD2/CLS_lab/fitbir_access_project</url>
<layout>default</layout>
</repository>
</distributionManagement>
<modelVersion>4.0.0</modelVersion>
<groupId>cls.lab</groupId>
<artifactId>fitbir_access</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.24</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
My application is connected to a MySQL database, I'm not sure if that has something to do with it.
Edit: Tried to run the following line in both Administrator: Windows PowerShell and Command Prompt, both with the same error "Could not find or load main class: mainWindow.java":
java -jar fitbir_access-1.0-SNAPSHOT-jar-with-dependencies.jar
Here is MANIFEST.MF Properties:
And here is what I get when I try to open MANIFEST.MF:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: audra
Build-Jdk: 16.0.1
Main-Class: mainWindow.java
Edit 2: Here is the file location for mainWindow.java: C:\Users\audra\OneDrive\Documents\NetBeansProjects\FITBIR\src\main\java\cls_lab\mainWindow.java
Compile classpath: C:\Users\audra.m2\repository\mysql\mysql-connector-java\8.0.24\mysql-connector-java-8.0.24.jar;C:\Users\audra.m2\repository\com\google\protobuf\protobuf-java\3.11.4\protobuf-java-3.11.4.jar;C:\Users\audra.m2\repository\com\h2database\h2\1.4.200\h2-1.4.200.jar;C:\Users\audra\OneDrive\Documents\NetBeansProjects\fitbir\target\classes
Runtime classpath: C:\Users\audra\OneDrive\Documents\NetBeansProjects\fitbir\target\classes;C:\Users\audra.m2\repository\mysql\mysql-connector-java\8.0.24\mysql-connector-java-8.0.24.jar;C:\Users\audra.m2\repository\com\google\protobuf\protobuf-java\3.11.4\protobuf-java-3.11.4.jar;C:\Users\audra.m2\repository\com\h2database\h2\1.4.200\h2-1.4.200.jar
And the boot classpath is like a page long so I won't post it unless it's necessary.
Edit 3: I changed the file locations so everything is under NetBeansProjects\fitbir (with lowercase letters), but this did not solve anything. I also changed the main class name in the pom file to cls_lab.mainWindow.java so that it is now the fully qualified class name, but I still have the same error when I run it through command prompt: Can not find or load main class.
I am on Eclipse 2019-09 and trying the following:
I created a file src/main/resources/build/build.properties to hold some information about the current build:
build.version=${project.version}
build.number=${buildNumber}
build.date=${buildTimestamp}
When building the project the variables get replaced correctly and the file inside the target folder is rendered correctly. When changing code in Eclipse (without a Maven build), the buildNumber gets replaced by its variable name.
I suppose it has something to do with m2e doing the filtering too often (not only when clicking build via the menu). The buildNumber is only available during the "real" build and so it is not available on other occasions, hence it is not getting replaced.
Can I tell Maven to only execute the variable replacement during a specific build phase?
Relevant excerpt from the pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>123</groupId>
<artifactId>456</artifactId>
<version>789</version>
<properties>
<maven.build.timestamp.format>dd.MM.yyyy HH:mm:ss</maven.build.timestamp.format>
<buildTimestamp>${maven.build.timestamp}</buildTimestamp>
</properties>
<!-- Dummy for Build Number Plugin -->
<scm>
<connection>scm:svn:http://127.0.0.1/dummy</connection>
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/dummy</url>
</scm>
<build>
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- Maven Build Number Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>buildnumber</id>
<phase>clean</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
</configuration>
</plugin>
</plugins>
</build>
</project>
Working example showing my problems:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.whatever</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
<project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
<maven-jar-plugin.version>3.5.0</maven-jar-plugin.version>
<maven.build.timestamp.format>dd.MM.yyyy HH:mm:ss</maven.build.timestamp.format>
<buildTimestamp>${maven.build.timestamp}</buildTimestamp>
</properties>
<!-- Dummy for Build Number Plugin -->
<scm>
<connection>scm:svn:http://127.0.0.1/dummy</connection>
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/dummy</url>
</scm>
<build>
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- Copy dependencies into target/lib -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create JAR -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.whatever.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Maven Build Number Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>buildnumber</id>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
</configuration>
</plugin>
</plugins>
</build>
</project>
Create a simple class org.whatever.test.Main.java with just a sysout:
package org.whatever.test;
public class Main {
public static void main(String... args) {
System.out.println("Hey!");
}
}
And create a build.properties under src/main/resources:
build.version=${project.version}
build.number=${buildNumber}
build.date=${buildTimestamp}
Building increases the build number by three. Changing your Main.java (causing recompilation) makes the replaced version of the build.properties in the target directory lose the build number.
EDIT: Fixed the by-three-incrementation. Thanks to khmarbaise. Still left with the replacing issue. https://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html states
Binds by default to the lifecycle phase: process-resources.
which comes just before compile. Eclipse probably does a compile on every code change (just guessing) and replaces the resources. On this phase no buildNumber is available (and I do not want to increase this number on every code change). I cannot find out how to bind to another phase or go a more elegant way.
EDIT: The more I am thinking about it the more I am thinking of keeping it this way. Building via Maven increments my build number. The build process also zips my class files, libraries etc. Inside the target directory and in the zip files, now there is the correct build number. Changing my code results in the build number being reset to ${buildNumber} in target/classes which is technically correct. I am not on the same build as I was before changing the code, I am somewhere between builds.
I think the build of Eclipse won't bother Maven's building.
The truely problem is the maven-resources-plugin invoked in 'process-resources' phase,and your buildnumber-maven-plugin runs after that.
Here is my solution here, hope it works for you.
https://stackoverflow.com/a/70604055/13049551
I have a test program that uses optaplanner. There is no direct use of KIE API's but it looks like they are being invoked behind the scenes. This may be related to the fact that I am using DROOLS for the score calculation. The program works from the IDE or through maven, but I want to create a standalone jar that will not require maven.
I used the maven assembly plugin to build a fat jar with all dependencies included to be run standalone.
When I run java -jar target/OptaPlannerTest-1.4-SNAPSHOT-jar-with-dependencies.jar I get :
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:27)
at org.kie.api.KieServices$Factory$LazyHolder.<clinit>(KieServices.java:332)
at org.kie.api.KieServices$Factory.get(KieServices.java:339)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:460)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
at com.github.wshackle.optaplannertest.Main.main(Main.java:38)
Caused by: java.lang.RuntimeException: Child services [org.kie.api.internal.assembler.KieAssemblers] have no parent
at org.kie.api.internal.utils.ServiceDiscoveryImpl.buildMap(ServiceDiscoveryImpl.java:186)
at org.kie.api.internal.utils.ServiceDiscoveryImpl.getServices(ServiceDiscoveryImpl.java:97)
at org.kie.api.internal.utils.ServiceRegistryImpl.<init>(ServiceRegistryImpl.java:36)
at org.kie.api.internal.utils.ServiceRegistryImpl$LazyHolder.<clinit>(ServiceRegistryImpl.java:32)
Line 38 of Main.java is only two lines into the application, so all it has done is load the config file and try to build the solver.
SolverFactory<Plan> solverFactory = SolverFactory.createFromXmlResource(
"com/github/wshackle/optaplannertest/solverConfig.xml");
Solver<Plan> solver = solverFactory.buildSolver();
solverConfig.xml is:
<solver>
<!-- Domain model configuration -->
<scanAnnotatedClasses>
<packageInclude>com.github.wshackle.optaplannertest.model</packageInclude>
</scanAnnotatedClasses>
<!-- Score configuration -->
<scoreDirectorFactory>
<scoreDrl>com/github/wshackle/optaplannertest/scoreRules.drl</scoreDrl>
</scoreDirectorFactory>
<!-- Optimization algorithms configuration -->
<termination>
<secondsSpentLimit>5</secondsSpentLimit>
</termination>
</solver>
In cast it is relevant my pom is this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.wshackle</groupId>
<artifactId>OptaPlannerTest</artifactId>
<version>1.4-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<optiplanner.version>7.3.0.Final</optiplanner.version>
<main.class>com.github.wshackle.optaplannertest.Main</main.class>
</properties>
<dependencies>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>${optiplanner.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${optiplanner.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The complete list of files in the jar is shown at
https://gist.github.com/wshackle/8887aac8a10e8c4b1f862a4bda288e41
I used grep to verify they seem to include the expected classes for each jar dependancy:
> grep -c org/kie/api jarlisting.txt
391
> grep -c org/kie/internal jarlisting.txt
364
> grep -c org/optaplanner/core jarlisting.txt
841
> grep -c org/drools/core jarlisting.txt
2175
> grep -c org/drools/compiler jarlisting.txt
832
The problem is that the following jar files all contain different versions of META-INF/kie.conf:
optaplanner-core-7.3.0.Final.jar
kie-internal/7.3.0.Final/kie-internal-7.3.0.Final.jar
drools-core-7.3.0.Final.jar
drools-compiler-7.3.0.Final.jar
When the maven-assembly-plugin puts them together only one version of the META-INF/kie.conf can be included. When building the solver the Optaplanner library will indirectly call getResources("META-INF/kie.conf") on the current Thread context classloader. If there are multiple jars on the classpath then all of them will be found and the resulting configuration will be the product of parsing all of them. In order to make this work in a single fat uber jar the kie.conf files need to be moved to different file names and a classloader overloaded to direct the library to use them at the new names. (It might also be possible to combine them into a single kie.conf file)
Extract and move the kie.conf files:
jar -xf ~/.m2/repository/org/optaplanner/optaplanner-core/7.3.0.Final/optaplanner-core-7.3.0.Final.jar META-INF/kie.conf
mv META-INF/kie.conf src/main/resources/optaplanner-core-kie.conf
jar -xf ~/.m2/repository/org/kie/kie-internal/7.3.0.Final/kie-internal-7.3.0.Final.jar META-INF/kie.conf
mv META-INF/kie.conf src/main/resources/kie-internal-kie.conf
jar -xf ~/.m2/repository/org/drools/drools-core/7.3.0.Final/drools-core-7.3.0.Final.jar META-INF/kie.conf
mv META-INF/kie.conf src/main/resources/drools-core-kie.conf
jar -xf ~/.m2/repository/org/drools/drools-compiler/7.3.0.Final/drools-compiler-7.3.0.Final.jar META-INF/kie.conf
mv META-INF/kie.conf src/main/resources/drools-compiler-kie.conf
Then overload and set the thread context loader.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
URL[] localKieConfUrls = new URL[]{
ClassLoader.getSystemResource("optaplanner-core-kie.conf"),
ClassLoader.getSystemResource("kie-internal-kie.conf"),
ClassLoader.getSystemResource("drools-core-kie.conf"),
ClassLoader.getSystemResource("drools-compiler-kie.conf")
};
ClassLoader newClassLoader = new ClassLoader(oldClassLoader) {
private final URL[] kieConfUrls = localKieConfUrls;
#Override
public Enumeration<URL> getResources(String name) throws IOException {
if ("META-INF/kie.conf".equals(name)) {
return new Enumeration<URL>() {
int index;
#Override
public boolean hasMoreElements() {
return index < kieConfUrls.length;
}
#Override
public URL nextElement() {
return kieConfUrls[index++];
}
};
}
return super.getResources(name);
}
};
Thread.currentThread().setContextClassLoader(newClassLoader);
I agree that the problem is as #WillSchackleford describes:
The problem is that the following jar files all contain different versions of META-INF/kie.conf:
optaplanner-core-7.3.0.Final.jar
kie-internal/7.3.0.Final/kie-internal-7.3.0.Final.jar
drools-core-7.3.0.Final.jar
drools-compiler-7.3.0.Final.jar
When the maven-assembly-plugin puts them together only one version of the META-INF/kie.conf can be included.
The best trick to combine all of these kie.conf files is to use a transformer in your maven config, like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.paconsulting.powerpeers.PowerPeersDemo</mainClass>
</manifest>
</archive>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/kie.conf</resource>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
This creates one META-INF/kie.conf file with the content of any of the kie.conf files it finds.
Run "mvn dependency:tree" and you'll see that optaplanner-core depends on kie-api, kie-internal-api, drools-core and drools-compiler. One of those will be missing in your fat jar.
I was having the same problem with the following pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
..
<dependencies>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>${optaPlanner.version}</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${jar.plugin.version}</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<compress>false</compress>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>${mainClass}</mainClass>
</manifest>
<index>true</index>
<manifestEntries>
<impl-version>${project.version}</impl-version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${dependency.plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly.plugin.version}</version>
<configuration>
<descriptors>
<descriptor>assembly/release.xml</descriptor>
</descriptors>
<finalName>${distribution.file.name}</finalName>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<workDirectory>${project.build.directory}/assembly/work</workDirectory>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Removing
<index>true</index>
solved my problem. Hope this helps others as well.
For people using maven-shade-plugin, here is a proposed fix that is going to merge the META-INF/kie.conf that are duplicated into a single file using the AppendingTransformer https://stackoverflow.com/a/53273253/5903731
I have also met this error but i found a solution with different way. Instead of generating a jar file with all dependencies, generating jar file with library folder of dependencies is easier way for getting runnable jar file. To produce jar file with lib folder modify your pom.xml file as indicated below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClassMain-Class</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
I am trying to evaluate JBoss Fuse as an integration platform, and I have the following question regarding deployment.
I am trying to set up a fabric and use profiles, more specifically feature repositories for camel/blueprint component deployment.
I am having the following issue with externalizing the component configuration: when i update the snapshot of the configuration file artifact, the configuration changes are not picked up by the container.
Moreover, when i completely remove the profile from the container, the PID config file stays on the server in etc/ folder.
Also there is an additional issue during deployment where the camel bundle gets activated before the config pid file is loaded, resulting in exception in aries blueprint, and i have to additionally refresh the osgi bundle manually.
Here is how the feature repository file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<features name="fuse-poc">
<feature name="fuse-poc-common" version="${project.version}">
<bundle>mvn:com.myorg.fuse/common/${project.version}</bundle>
</feature>
<feature name="fuse-poc-camel" version="${project.version}">
<feature>fuse-poc-common</feature>
<config name="com.myorg.fuse.poc.camel">
test.value=ENC(5XdDgfKwwhMTmbo1z874eQ==)
</config>
<bundle>mvn:com.myorg.fuse/fuse-poc-camel/${project.version} </bundle>
</feature>
<feature name="fuse-poc-activemq" version="${project.version}">
<feature>fuse-poc-common</feature>
<configfile finalname="etc/com.myorg.fuse.poc.jms.cfg">
mvn:com.myorg.fuse/feature/${project.version}/cfg/dev
</configfile>
<bundle>mvn:com.myorg.fuse/fuse-poc-camel- activemq/${project.version}</bundle>
</feature>
</features>
The projects themselves are simple camel archetype projects with one having a basic route with logging and one with route using activemq and cm:property-placeholder in blueprint.xml
Here is the corresponding build section in maven:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.myorg.fuse</groupId>
<artifactId>fuse-poc-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>feature</artifactId>
<packaging>pom</packaging>
<name>FUSE PoC Feature Repository</name>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>filter</id>
<phase>generate-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/classes/fuse-poc.xml</file>
<type>xml</type>
<classifier>features</classifier>
</artifact>
<artifact>
<file>src/main/resources/env/dev/com.myorg.fuse.poc.jms.cfg</file>
<type>cfg</type>
<classifier>dev</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here are the commands I use to deploy the feature:
fabric:version-create 1.1
fabric:profile-create --parent jboss-fuse-full fuse-poc
fabric:profile-edit --repository mvn:com.myorg.fuse/feature/1.0.0-SNAPSHOT/xml/features fuse-poc 1.1
fabric:profile-edit --feature fuse-poc-camel fuse-poc 1.1
fabric:profile-edit --feature fuse-poc-activemq fuse-poc 1.1
fabric:container-upgrade 1.1 root
fabric:container-add-profile root fuse-poc
After I manually do osgi:refresh <bundle id> the bundle it starts fine.
fabric:container-remove-profile root fuse-poc
All the config pid entries stay in the config, and all osgi bundles are also staying installed. How do i correctly undeploy artifacts so that the container is clean and an updated version of the same artifact can be deployed without side effects?
I suspect i am doing something conceptually wrong, because ultimately the issue above leads to the following problem: if i add a property to either the element in features, or the .cfg file and install the project using maven again, and then do container-remove-profile, profile-refresh, and container-add-profile, the config does not change at all. It can only be redeployed correctly if i manually do the config:delete command on my pid in the console.
So I finally had time to dig through the sources and cross-reference karaf, fabric and jboss documentation.
Here is how it works:
The code responsible for loading/unloading bundles through the feature repository system is located in fabric-agent-1.2.0.redhat-621084.jar
Notably, the class io.fabric8.agent.service.FeatureConfigInstaller is responsible for the configuration entries, and the class io.fabric8.agent.service.Agent is doing the overall deployment
There is no code at all to uninstall the config file/remove config entries. This makes it troublesome to do development with SNAPSHOTs
However, there is a useful 'override' property that can be specified on the <configfile> element - if it is set to true, the config PID file will be overwritten on deployment which is exactly what i wanted for local development
For <config> element, there is an undocumented 'append' property, which, when set to true, is supposed to append new entries to the config. However, it is hilariously bugged - turns out it also removes all defined previously existing properties when trying to append. Conclusion - use <configfile> functionality instead
Additionally, for externalizing environment configuration i've come to the conclusion the most simple way is to produce multiple feature xml descriptors from the same file through different maven build profiles. The project files consequently look like this:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.myorg.fuse</groupId>
<artifactId>fuse-poc-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>feature</artifactId>
<packaging>pom</packaging>
<name>FUSE PoC Feature Repository</name>
<properties>
<build.environment>dev</build.environment>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>filter</id>
<phase>generate-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/classes/fuse-poc.xml</file>
<type>xml</type>
<classifier>features-${build.environment}</classifier>
</artifact>
<artifact>
<file>src/main/resources/env/${build.environment}/com.myorg.fuse.poc.cfg</file>
<type>cfg</type>
<classifier>${build.environment}</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local</id>
<properties>
<build.environment>local-dev</build.environment>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<build.environment>dev</build.environment>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<build.environment>uat</build.environment>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.environment>prod</build.environment>
</properties>
</profile>
</profiles>
</project>
feature.xml:
<?xml version="1.0" encoding="UTF-8"?>
<features name="fuse-poc">
<feature name="fuse-poc-common" version="${project.version}">
<bundle>mvn:com.myorg.fuse/common/${project.version}</bundle>
</feature>
<feature name="fuse-poc-camel" version="${project.version}">
<feature>fuse-poc-common</feature>
<configfile finalname="etc/com.myorg.fuse.poc.cfg" override="true">
mvn:com.myorg.fuse/feature/${project.version}/cfg/${build.environment}
</configfile>
<bundle>mvn:com.myorg.fuse/fuse-poc-camel/${project.version}</bundle>
</feature>
</features>
This way you can directly specify the environment when creating the profile for deploying the feature:
fabric:profile-create --parent jboss-fuse-full fuse-poc fabric:profile-edit --repository mvn:com.myorg.fuse/feature/1.0.0-SNAPSHOT/xml/features-local-dev fuse-poc
Note to set up the build integration tool to build the feature module for all profiles except 'local-dev', since that one needs to be used by developers locally and should not be downloaded from the central repository
On a final note, once i resolved the config handling issues and the bundles started deploying correctly, the platform also started undeploying bundles correctly on removing the profile from the container. I suspect there is some issue with uninstalling the bundles whenever the original deployment ended in failure
I have a project with a POM that looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>my-parent</artifactId>
<groupId>com.company</groupId>
<version>2</version>
</parent>
<groupId>com.company</groupId>
<artifactId>resources-silo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>Some EJB component</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>simple-command</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- some jars ... -->
</dependencies>
</project>
I want to use m2eclipse with m2e-wtp to deploy this project to Glassfish 3. However, m2e-wtp does not deploy the dependencies. I know that building superjars with jar-with-dependencies is probably not the way to go for EJB projects, but I cannot really change this without messing up the customer's build / deployment processes.
So, the problem is that the deployment assembly wizard does not display the maven dependencies:
I need a solution that works without changing the pom.xml, since that would disturb the customer's build processes. I am aware that using an EAR would be the preferred solution here.
Is the behaviour that I'm seeing a bug or is it an inherent limitation in the way m2e-wtp and the ejb packaging work?
Is it even possible to have m2e-wtp extract dependency jars into the deployed application?