weblogic-maven-plugin appc goal 12.1.3. weblogic.utils.compiler.ToolFailureException: [J2EE:160127]ERROR: Could not delete previous archive - weblogic12c

If you are experience issues with maven and the appc goal with the maven plugin resulting in:
weblogic.utils.compiler.ToolFailureException: [J2EE:160127]ERROR: Could not delete previous archive
then read my answer below

This solution worked for me.
Firstly the order of the application.xml is important
if you are using the maven-ear-plugin, then ensure all of the modules listed are in dependency order in the pom
<modules>
<ejbModule></ejbModule>
</modules>
if not ensure that your application.xml is in dependency order
<module>
<ejb>rng.jar</ejb>
</module>
etc.
To clarify what i mean by dependency order.
If A depends on C, B depends on A, C depends on nothing.
The order of specification should be C, A, B.
Secondly it seems there is some kind of validation on having EJB dependencies which are not necessary (you use none of the classes of that EJB). Using the first method I was able to reduce this down to 1 jar not being deleted. After this all of my jars were deleted from the temp directory.
The directory for reference was:
C:\Users\user\AppData\Local\Temp\appcgen_1439472796562_application.ear

Related

Unittesting pomless aspectJ project

In a Tycho build I have a pomless plugin-project/bundle A with some aspectj classes in it (*.aj). The project builds fine and another project B can reference project A via its manifest.mf.
Now a separate unittest project C exists for testing project A. This unittest project C is intended to be build with standard pom.xml and maven-surefire (no manifest.mf exists in C).
The problem is that C cannot find the *.aj classes of project A. If I introduce a pom.xml in project A with maven-aspectj-plugin then A can be build and C finds anything it needs in A. But then project B cannot find bundle A. Are there any suggestions to resolve such a problem?
I'm relativly new to Tycho and i assume the problem belongs to the mix of the pom-less approach in project A and the pom-based approach in unittest project C. Is there any possibility to build the mentioned unitest project C pom-based or do i need to build it with tycho-surefire ?
I found this related question
Aspectj class is not found by test class when running test with maven
but it didn't help for me in this case.
Thanks in advance.
pom.xml should be used in project A, with packaging type eclipse-plugin, no dependencies set, and the usual plugin setup of aspectj-maven-plugin

Liquibase resource found in both Maven target and Maven repository

I have Eclipse Maven GWT project and I added flowable-form-engine dependency that uses Liquibase. Liquibase is searching for changelog file org/flowable/form/db/liquibase/flowable-form-db-changelog.xml but finds two!
org.flowable.common.engine.api.FlowableException: Error initialising form data schema
at org.flowable.form.engine.impl.db.FormDbSchemaManager.initSchema(FormDbSchemaManager.java:58)
at org.flowable.form.engine.impl.cmd.SchemaOperationsFormEngineBuild.execute(SchemaOperationsFormEngineBuild.java:29)
at org.flowable.form.engine.impl.cmd.SchemaOperationsFormEngineBuild.execute(SchemaOperationsFormEngineBuild.java:24)
at org.flowable.common.engine.impl.interceptor.DefaultCommandInvoker.execute(DefaultCommandInvoker.java:10)
at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53)
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:71)
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
at org.flowable.form.engine.impl.FormEngineImpl.<init>(FormEngineImpl.java:45)
at org.flowable.form.engine.FormEngineConfiguration.buildFormEngine(FormEngineConfiguration.java:172)
at org.flowable.form.engine.configurator.FormEngineConfigurator.initFormEngine(FormEngineConfigurator.java:83)
at org.flowable.form.engine.configurator.FormEngineConfigurator.configure(FormEngineConfigurator.java:63)
at org.flowable.common.engine.impl.AbstractEngineConfiguration.configuratorsAfterInit(AbstractEngineConfiguration.java:859)
at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:985)
at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:887)
at sk.dominanz.coarui.server.services.WorkflowServiceAdditional.<clinit>(WorkflowServiceAdditional.java:64)
... 33 more
Caused by: liquibase.exception.ChangeLogParseException: Error Reading Migration File: Found 2 files that match org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:118)
at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15)
at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:217)
at liquibase.Liquibase.update(Liquibase.java:190)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.Liquibase.update(Liquibase.java:175)
at liquibase.Liquibase.update(Liquibase.java:168)
at org.flowable.form.engine.impl.db.FormDbSchemaManager.initSchema(FormDbSchemaManager.java:52)
... 48 more
Caused by: java.io.IOException: Found 2 files that match org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
at liquibase.util.StreamUtil.singleInputStream(StreamUtil.java:206)
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:71)
... 55 more
So I debugged it and it finds one resource from target directory:
jar:file:/C:/work/git/coarui/target/Main-1.0-SNAPSHOT/WEB-INF/lib/flowable-form-engine-6.4.0.jar!/org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
and other resource from maven repository:
jar:file:/C:/Users/Piro/.m2/repository/org/flowable/flowable-form-engine/6.4.0/flowable-form-engine-6.4.0.jar!/org/flowable/form/db/liquibase/flowable-form-db-changelog.xml
Is there a way to ignore one of them, or is my build path or dependency definition wrong?
My build path contains:
src/main/java sources
src/test/java sources
JRE System library
Maven dependencies (in C:/Users/Piro/.m2/repository...)
JUnit4
Looking at source code resources are read classLoader.getResources(path); where class loader is jetty class loader JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.
In my run/debug configuration I have classpath similar to build path plus GWT library gwt-dev-2.8.1.jar - C:\Users\Piro\.m2\repository\com\google\gwt\gwt-dev\2.8.1
In pom.xml dependency is defined as:
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-engine-configurator</artifactId>
<version>${flowableVersion}</version>
</dependency>
Maven GWT plugin groupId=net.ltgt.gwt.maven, artifactId=gwt-maven-plugin has configuration parameter classpathScope but I tested <classpathScope>compile+runtime</classpathScope>, <classpathScope>compile</classpathScope> and <classpathScope>runtime</classpathScope> and the same error occurs.
Searching the internet I found similar posts on flowable forum (1, 2) but no solution is provided.
This generally happens when you mix client and server code in the same Maven module, and given how GWT works there's no (easy) around that, besides splitting your code in separate client and server (and possibly shared) Maven modules.
You can have a look at https://github.com/tbroyer/gwt-maven-archetypes for examples (disclaimer: I'm the author, but also a member of GWT's Steering Committee)
it seems that for some reason your .m2 is in the classpath. If it really makes sense to you then you can try to use <scope>provided</scope> in a pom where you declare dependency to flowable-form-engine-configurator. However you may decide to exclude .m2 from classpath which is better I think.

How to make JUnit4 + Hamcrest 1.3 + Mockito work from Eclipse AND Tycho

I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work in Eclipse so that when I add them as dependencies, my tests will run.
(The way I've done this is using the p2-maven-plugin to bundle the following
artifacts from Maven Central into plugins/a feature and provide them via P2:
junit 4.12
org.mockito.mockito-core 2.8.47
org.hamcrest.all 1.3.0
Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.
However, the Tycho build of the same fragment will fail with the
following messages:
java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
So it seems that some other plugin is loading the package
org.hamcrest.Matcher before my fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.
Does anyone have an idea -- or even better: a working example -- of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build)?
Seems like that the loader want the dependencies in a bundle.
But I guess you haven't put your test lib in a bundle.
You could try to add them in the dependencies of your product to see how it reacts.
Background
The root of the problem is, that org.junit already has a dependency to org.hamcrest.core. So when your test-plugins has a dependency to org.hamcrest.all (which contains everything of hamcrest-core and all other hamcrest artifacts), all classes specified in hamcrest-core exist twice. Once in the bundle of hamcrest-core and once in hamcrest-all, which is why you get the linkage error.
If you open the Manifest of org.junit in the Manifest-Editor of Eclipse and go to the 'Dependencies' tab it should show you org.hamcreast.core in the "Required Plug-ins" section and org.hamcreast.core should be re-exported. Or in the raw-manifest it should look like this:
Require-Bundle: org.hamcrest.core;bundle-version="1.3.0";visibility:=reexport
Solution 1 - add hamcrest sub-modules
Instead of adding the all hamcrest-modul containing hamcrest.all as dependency to my Eclipse test-bundle/project (via 'Require-Bundle'), I add the hamcrest sub-modules that I require, except for hamcrest-core (because it is already re-exported in my case). For me hamcrest-library was sufficient.
The available hamcrest sub-modules are (according to the org.hamcrest:hamcrest-parent pom, which can be found here: https://repo1.maven.org/maven2/org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom):
hamcrest-core
hamcrest-library
hamcrest-generator
hamcrest-integration
Creating the p2-Repo containing the required bundles
When using Maven and the 'org.reficio:p2-maven-plugin' to build the p2-repo that contains the mentioned test-bundles, the conversion of the maven-artifacts to OSGi-bundles does not produce fully working results by default.
Converting a maven-module to a full OSGi-bundle consists mainly of configuring the MANIFEST.MF to contain proper entries. For this the p2-maven-plugin utilizes "bnd tool".
By default the Java packages provided by all maven dependencies of a maven module are added as optional Imported-package when that module is converted into a OSGi-bundle.
In my case this had the consequence that the org.hamcrest.library bundle refereed to the packages from hamcrest-core only via Import-Package in its MANIFEST.MF.
But unfortunately with only this specified, the Equinox-ClassLoader did not find the classes from hamcrest-core in the test-runtime and threw a corresponding exception. Maybe this is also caused by the fact that hamcrest-core and hamcrest-library have a package "org.hamcrest" and bnd-tools adds the exported packages of a bundle to the imported packages again.
The solution in my case was to instruct the org.reficio:p2-maven-plugin respectively bnd-tools to add org.hamcrest.core as "Require-Bundle" to the Manifest of hamcrest-library. For this, the instructions-element shown below needs to be add to the artifact-element of org.hamcrest:hamcrest-library in the execution-configuration of the 'p2-maven-plugin' in the pom.xml used to build the p2-repo:
<artifact>
<id>org.hamcrest:hamcrest-library:1.3</id>
<instructions>
<Require-Bundle>org.hamcrest.core</Require-Bundle>
</instructions>
</artifact>
If hamcrest sub-modules other than hamcrest-library are are used, the instructions need to be analogous, corresponding to the dependencies listed in their pom.
Edit
Eclipse Orbit provides org.hamcrest.library, org.hamcrest.integrator and org.hamcrest.generator bundles that have have org.hamcrest.core as required bundle (if necessary):
https://download.eclipse.org/tools/orbit/downloads/
Appendix
In the end first solution caused a SecurityException:
java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
Which is a known issue. The following two solutions avoid this issue and work properly during Tycho builds and from within Eclipse.
Solution 2 - bundle hamcrest sub-module jars with a plug-in
Another approach is to download the jar of the required hamcrest sub-module and bundle it with a Eclipse plugin directly, like it is described here:
https://www.vogella.com/tutorials/Hamcrest/article.html#hamcrest_eclipse
To bundle the jar with a plug-in, include it in the project and add it to the plug-ins classpath. Go to the Runtime-Tab of the Manifest-Editor and klick Add... in the Classpath section and select the jar. This should add the jar to the .classpath, MANIFEST.MF and build.properties file properly.
Make sure the jar is included before the other plug-in dependencies (which include hamcrest-core), as stated in the mentioned tutorial.
If hamcrest should be used in multiple test-projects/fragments, add the jar to a test plug-in all other test-projects depend on.
Solution 3 - use org.hamcrest 2.x
Since hamcrest-2 there is only one org.hamcrest jar/artifact that includes everything from hamcrest. Using hamcrest 2 avoids all the issues and is my preferred solution. Except for the changed packaing of hamcrest the API did not break, so it should be sufficient to just include org.hamcrest:
https://github.com/hamcrest/JavaHamcrest/releases/tag/v2.1
In order to create a p2-repo that includes org.hamcrest-2.2 the following sippet has to be included into the configuration-artifacts element of the p2-maven-plugin execution in the pom.xml:
<artifact>
<id>org.hamcrest:hamcrest-core:2.2</id>
<instructions>
<Require-Bundle>org.hamcrest;bundle-version="2.2.0";visibility:=reexport</Require-Bundle>
</instructions>
</artifact>
<artifact>
<id>org.hamcrest:hamcrest:2.2</id>
</artifact>
The IUs org.hamcrest.core 2.2 and org.hamcrest have to be included in the target-platform to make them available for plug-ins in Eclipse and during. All plug-ins which depend on org.junit now have org.hamcrest also available.
This aproach works because org.hamcrest.core still exists in version 2 stream, even tough it is deprected and empty. Its only purpose is to redirect build-systems to the new org.hamcrest-2.x jar/artifact. Therefore org.hamcrest.core-2.2 specifies a compile dependency to
org.hamcrest-2.2 in its pom.xml. Unfortunately the p2-maven-plugin dosn't translate it directly into a bundle-requirement for org.hamcrest in the manifest, but with the sippet above enforces that.
Because org.junit requires the bundle org.hamcrest.core with a minimal version of 1.3 (but without upper-bound) it uses the present org.hamcrest.core-2.2 . org.hamcrest.core-2.2 again requires org.hamcrest-2.2 and re-exports it. This makes org.junit use org.hamcrest-2.2 in the end and because org.junit re-exports hamcrest-core it also provides org.hamcrest-2.2 immediately to all depended plug-ins.
Note
If you want to play around with different variants of a jar, don't forget to clear (means delete on the drive) the bundle pools of Maven (in <your-home>/.m2/repository/p2/osgi/bundle/ and Eclipse PDE (in <your-workspace>/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/) in between. Otherwise you will always use the first one, because jar's with the same version are not updated.

Access CQ5 project bundles on same instance

I have two project bundles my local CQ/AEM server. Project A contains some java Util class methods which can be utilized in project B as well.
While developing, how do I import my project A classes in project B to access the methods so that I do not have to duplicate the methods again?
I tried adding dependency in my Project B bundle pom.xml as below. Is this correct?
<dependency>
<groupId>com.project-a</groupId>
<artifactId>cq-project-a</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
I get missing artifact error for this.
"Missing artifact com.project-a:cq-project-a:jar:1.0-SNAPSHOT"
Please suggest how the import can be done.
Thanks
I guess you forgot to build project a using mvn install. The dependency will be searched in your local maven repo.
This solution may fix you issue: update your pom.xml on project a, modify groupId, artifactId, version, packaging tags and make sure they look likes:
<groupId>com.project-a</groupId>
<artifactId>cq-project-a</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
Then run mvn clean install on project a, run mvn clean install one more time one project b. I applied this to my last project, I hope it works for you.

Maven add custom multiple jars from folder

I have a custom list of jars around 40 jars in a libs folder. I want to add all as a maven dependenices.
+ project
pom.xml
+ src
+ libs
Is there any way by that add all jar at a time.
Maven manages dependencies rather different than just including jars.
Essentially if you have a dependency on A and A uses B, you will need to have both A+B in your lib folder, but only A in your maven project, because maven transitively will include the subdependencies.
You should probably look through the maven repository, and see if you can find the jar files there in a similar version, and include that instead.
i.e. if you have commons-collections4-4.0.jar, use http://search.maven.org and write commons-collections4, and you will see a list of candidates. probably some with multiple version. Note, maven uses a groupId to scope jar files, so pick one with a suitable groupId, in this case org.apache.commons (Since commons-collections is an apache.org project).
When you have identified your dependency, it will show you ways to include it in your build, e.g. for maven, it would be
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
Looking at the pom file, you will be able to spot potential subdependencies, but otherwise, once you have added the dependency to your <dependencies/> section of your pom, run a mvn dependency:tree or mvn dependency:list to see how dependencies are transitively included.
Should you end up with libraries you cannot find in maven central, read this guide for the rest http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Found one wonderfull plugin to achieve this task. addjars-maven-plugin