I currently try to migrate an old Java EE solution that connects via RFC to a SAP-System to an approach with Quarkus.
As the project uses maven, I face again the issue of the sapjco3.jar library from SAP that prevents the library from being renamed.
If I add the library as dependency like that
<dependency>
<groupId>com.sap</groupId>
<artifactId>sapjco3</artifactId>
<version>3.1</version>
</dependency>
it will be added to the lib-directory with the name com.sap.sapjco3-3.1.jar.
Unfortunately that ends up in an excpetion
java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "com.sap.sapjco3-3.1.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
There are already some articles on Stackoverflow describing that issue and there is also a SAP-note on that: https://apps.support.sap.com/sap/support/knowledge/en/2182414
So I solved the issue in the "old" approach, setting the dependency to provided and copying it with the maven-dependency-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>sapjco3</includeArtifactIds>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
Unfortunately that does not work with quarkus.
In development if I use
mvn quarkus:dev
the provided seems to be ignored and I still get the message.
JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.1.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
If I pack it and try to deploy it to a docker-container
mvn clean package
it basically works to copy the jar-file to the lib-directory, if I change the copy to another phase in the pom.xml
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
but I get build warnings first:
[WARNING] [io.quarkus.arc.processor.BeanArchives] Failed to index com.sap.conn.jco.ext.DestinationDataProvider: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader
[INFO] [io.quarkus.arc.processor.IndexClassLookupUtils] Class for name: com.sap.conn.jco.ext.DestinationDataProvider was not found in Jandex index. Please ensure the class is part of the index.
and later the following error:
java.lang.NoClassDefFoundError: com/sap/conn/jco/ext/DestinationDataProvider
Is there a solution with Quarkus to deal with provided dependencies and copy them manually with maven?
I have the SAP library working with Quarkus in a project. The solution is not specific to Quarkus (the same solution is used by Spring Boot projects).
First, define the library with a system scome so that its name is not modified.
<dependency>
<groupId>com.sap</groupId>
<artifactId>sapjco3</artifactId>
<version>3.1</version>
<scope>system</scope>
<systemPath>${project.build.directory}/dependency/sapjco3.jar</systemPath>
</dependency>
Then, configure the maven-dependency-plugin to copy the library in this path in the initialize phase and to include it in the final package. It also contains configuration for the native lib used by the sapjco3.jar library.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-jco-libs-unit-tests</id>
<phase>initialize</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<outputDirectory>${lib.directory}</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>${sap.jco.version}</version>
<overWrite>true</overWrite>
<destFileName>sapjco3.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-native-lib-for-unit-tests</id>
<phase>process-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<outputDirectory>${native.lib.directory}</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>${sap.jco.version}</version>
<type>${envType}</type>
<classifier>${envClassifier}</classifier>
<overWrite>true</overWrite>
<destFileName>${native.lib.filename}.${envType}</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Last, configure which native lib should be included thanks to profiles, one profile by OS/CPU arch is needed. Here is the configuration:
<profiles>
<!-- Manage JCO native deps by OS arch -->
<profile>
<id>windows-x86_64</id>
<activation>
<os>
<family>windows</family>
<arch>x86_64</arch>
</os>
</activation>
<properties>
<envClassifier>ntamd64</envClassifier>
<envType>dll</envType>
<native.lib.filename>sapjco3</native.lib.filename>
</properties>
</profile>
<profile>
<id>windows-amd64</id>
<activation>
<os>
<family>windows</family>
<arch>amd64</arch>
</os>
</activation>
<properties>
<envClassifier>ntamd64</envClassifier>
<envType>dll</envType>
<native.lib.filename>sapjco3</native.lib.filename>
</properties>
</profile>
<profile>
<id>linux-x86_64</id>
<activation>
<os>
<name>linux</name>
<arch>x86_64</arch>
</os>
</activation>
<properties>
<envClassifier>linuxx86_64</envClassifier>
<envType>so</envType>
<native.lib.filename>libsapjco3</native.lib.filename>
</properties>
</profile>
<profile>
<id>linux-amd64</id>
<activation>
<os>
<name>linux</name>
<arch>amd64</arch>
</os>
</activation>
<properties>
<envClassifier>linuxx86_64</envClassifier>
<envType>so</envType>
<native.lib.filename>libsapjco3</native.lib.filename>
</properties>
</profile>
<profile>
<id>macosx-x86_64</id>
<activation>
<os>
<name>mac os x</name>
<arch>x86_64</arch>
</os>
</activation>
<properties>
<envClassifier>darwinintel64</envClassifier>
<envType>dylib</envType>
<native.lib.filename>libsapjco3</native.lib.filename>
</properties>
</profile>
<profile>
<id>macosx-amd64</id>
<activation>
<os>
<name>mac os x</name>
<arch>amd64</arch>
</os>
</activation>
<properties>
<envClassifier>darwinintel64</envClassifier>
<envType>dylib</envType>
<native.lib.filename>libsapjco3</native.lib.filename>
</properties>
</profile>
With all this, test works, mvn quarkus:dev works, and a package done with mvn clean package works.
Be careful that the initialize phase of Maven is not launched by default, you need to call mvn initialize once for the library copy to happens.
We were struggling and working around with the naming-problem of the sapjco3.jar until I stumbled upon a footnote on this link: https://help.mulesoft.com/s/article/It-is-not-allowed-to-rename-or-repackage-the-original-archive-sapjco3-jar
Name your artifact com.sap.conn.jco.sapjco3.jar and it will solve the naming problem, as the driver accepts this name even with versions numbers added.
Your next stumbling block will then be the native library though ... I don't have a solution for that part in a quarkus environment, as I didn't try that yet.
Related
I've got a big issue with the integration of JaCoCo maven plugin for the code covering of SonarQube 6.0.
I've got a multi-module Maven project lets say :
master
|--core
|--web
|--process
in the master pom.xml, I've setted a reporting profile like that :
<profile>
<id>reporting</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-unit-test</id>
<!--<phase>test</phase> -->
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file to write the execution data to. -->
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Connection with SureFire plugin -->
<propertyName>sonarUnitTestArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to where the execution data is located. -->
<dataFile>${sonar.jacoco.reportPath}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${jacoco.ut.outputdir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>${sonarUnitTestArgLine} -XX:MaxPermSize=512M -Xms512m -Xmx512m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
in the childs, I overload the configuration by adding some exclusions :
<!-- First attempt -->
<properties>
<sonar.jacoco.excludes>**/model/**/*</sonar.jacoco.excludes>
</properties>
<!-- Second attempt -->
<properties>
<sonar.coverage.exclusions>**/model/**/*</sonar.coverage.exclusions>
</properties>
<!-- Third attempt -->
<profiles>
<profile>
<id>reporting</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- Exclude model classes (POJO's) -->
<exclude>**/model/**/*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
the idea here is to remove the Pojo of the code coverage ( we also do it for other types of Class ...)
When I run the mvn command line :
mvn clean generate-sources install verify -P reporting -fn
All my reports are well generated but in Sonar, the exculsions aren't been taking into account ...
Please can you help me fixing this issue ?
After a lot of reasearch, I've found the solution for this problem, I post the answers to help poeple ho'll have the same issue :
In the master-module
<properties>
<sonar.coverage.exclusions>
**/patternA/**/*,
**/patternB/**/*
</sonar.coverage.exclusions>
</properties>
In the sub-modules
<profiles>
<profile>
<id>report</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- Exclude model classes (POJO's) -->
<exclude>**/patternA/**/*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
in the master pom
I tried adding just the below details in properties section and it worked for me.
<sonar.coverage.exclusions>
**/patternA/*.java,
**/patternB/*.java
</sonar.coverage.exclusions>
I had a maven project structure including following projects
server
client
node
This is my module structure in main pom
<modules>
<module>server</module>
<module>node</module>
<module>help</module>
<module>client</module>
</modules>
I defined an automatic jar creation mechanism that runs on server machine. It checkouts code for each module, compiles, builds, etc. In each module, I defined maven scm blug in for checking out latest code for related module (Server, client , node).
For example, this is pom.xml for server side.
<scm>
<connection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/server/src</connection>
<developerConnection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/server/src</developerConnection>
</scm>
And this is profile for refreshing
<profile>
<id>environment-refresh-sources</id>
<activation>
<property>
<name>refreshSources</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<username>maven.user</username>
<password>password</password>
<checkoutDirectory>${basedir}/src</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>CheckoutFromSVN</id>
<phase>initialize</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
We have this configuration for each module. Just scm connection is changing. For example: this is for client.
<connection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/client/src</connection>
Now I am trying to migrate from SVN to GIT. But I am not able to configure maven plug in to work in this way.
This is my scm configuration for GIT.
<scm>
<connection>scm:git:http://maven.user#ip/scm/sig/project.git</connection>
<developerConnection>scm:git:http://maven.user#ip/scm/sig/project.git</developerConnection>
</scm>
This is my new plugin for git. I have added branch part. Now it checkouts master branch including server, client etc. modules. How can I work in same way with GIT.
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<connectionType>developerConnection</connectionType>
<scmVersion>master</scmVersion>
<scmVersionType>branch</scmVersionType>
<username>maven.user</username>
<password>password</password>
<checkoutDirectory>${basedir}/src</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>CheckoutFromGIT</id>
<phase>initialize</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
Is there way to skip generate-sources in Maven?
Doing it via command line options
I've scenario where I generate CXF classes when ever I there is change in WSDL or WADL. Hence I generate it explicitly whenever I need. Hence I created a separate profile a new profile cxf-gen along with my usual dev, uat, syst. which has plugins to generate the classes. In short whenever I need to regenerate the classes I switch to the profile and run generate-sources. Here is sample profile I use.
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<envName>dev</envName>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<envName>uat</envName>
</properties>
</profile>
<profile>
<id>jaxB-gen</id>
<properties>
<envName>dev</envName>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<!-- CONFIGS ->
</configuration>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>code-gen</id>
<properties>
<envName>dev</envName>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- CONFIGS ->
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- wadl2java Required only when JAXRS classes are to be generated -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-wadl2java-plugin</artifactId>
<version>2.7.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- CONFIGS ->
</configuration>
<goals>
<goal>wadl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.googlecode.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.3.7</version>
<configuration>
<!-- CONFIGS ->
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This command line option should work if you are using maven-source-plugin (works with Maven 3.6.0):
-Dmaven.source.skip=true
This is an old question and although some answers would somehow work none of them are ideal.
This answer does not break clean builds: calling "mvn <goal>" still produces the expected and backward-compatible result, which is good for continuous integration. Also this answer does not rely on committing generated code to version control, which is a bad idea as it might become out of sync with the source.
I am assuming the generate-sources phase is bound to a plugin goal.
The answer is to create a profile called "clean-build" which is active by default and contains your plugin binding. When a developer trusts they can safely skip generate-sources they may run the following.
mvn -P !clean-build <goal>
Or if the exclamation mark needs to be escaped.
mvn -P \!clean-build <goal>
Here is what the pom.xml might look like.
<profiles>
<profile>
<id>clean-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
...
<executions>
<execution>
...
<phase>generate-sources</phase>
...
</execution>
</executions>
...
</plugin>
</plugins>
</build>
</profile>
</profiles>
This answer requires Maven 2.0.10+.
I have a Maven (3.0.4) project in which process some external resources, and filtering them using some properties defined in a profile.
When I launch the assembly plugin (either manually or hooked to a phase) it seems that maven-resource-plugin does not consider active the profile specified by command line. In this way the tokens which relate to the properties defined in the specified profile are not replaced.
If I define a profile activeByDefault this is considered to be active even if another is specified by command line...
This is the example:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-script</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/bash</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
...
<profiles>
<profile>
<id>staging</id>
<properties>
<remote.url>some_stag_value</remote.url>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<remote.url>some_prod_value</remote.url>
</properties>
</profile>
</profiles>
Try deactivating the profile using !:
mvn groupId:artifactId:goal -P profile_you_want !default_profile
I have separated a Java EE project in the following submodules:
project-war
project-ejb
project-ear
project-test
I also have a root pom which includes the above modules. Since I have tests in a separate project, theres no point in running the test phases in the 3 first modules, as theres no point in compiling or packaging the last module since it only contains tests for the other 3 modules. My question is : How can I remove the test phases from the first 3 modules and how can I remove the other phases from the test project?
You can do that by setting up different profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
exp:
<profile>
<id>deploywar</id>
<build>
<plugins>
<plugin>
<groupId>net.fpic</groupId>
<artifactId>tomcat-deployer-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>pos</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<host>${deploymentManagerRestHost}</host>
<port>${deploymentManagerRestPort}</port>
<username>${deploymentManagerRestUsername}</username>
<password>${deploymentManagerRestPassword}</password>
<artifactSource>
address/target/addressservice.war
</artifactSource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Defines the QA deployment information -->
<profile>
<id>qa</id>
<activation>
<property>
<name>env</name>
<value>qa</value>
</property>
</activation>
<properties>
<deploymentManagerRestHost>10.50.50.50</deploymentManagerRestHost>
<deploymentManagerRestPort>58090</deploymentManagerRestPort>
<deploymentManagerRestUsername>
myotherusername
</deploymentManagerRestUsername>
<deploymentManagerRestPassword>
myotherpassword
</deploymentManagerRestPassword>
</properties>
</profile>
Which you would call the deploywar profile in a cli with mvn -Pdeploywar -Denv=dev clean install