DefaultChemObjectBuilder ClassNotFoundException occur when running jmh benchmark in terminal Intellij Idea - maven

I can run the project as an application in IntelliJ IDEA by using main method. But when I'm trying to run it using terminal for benchmark, a class not found exception occurs.
public class MyBenchmark {
#Benchmark
public static void sdfIterativeReader() throws ClassNotFoundException, FileNotFoundException {
File sdfFile = new File("molecule.sdf");
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IteratingSDFReader reader = new IteratingSDFReader(new FileInputStream(sdfFile),builder);
while (reader.hasNext()) {
IAtomContainer molecule = (IAtomContainer) reader.next();
IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula(molecule);
String molecularFromula = MolecularFormulaManipulator.getString(formula);
System.out.println(molecularFromula);
}
}
}
I used the command: mvn clean install then project is building successfully. When I run the command:
java -jar target/benchmarks.jar
it gives the following error:
Here, I have attached my 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>
<groupId>org.chemid</groupId>
<artifactId>chemid-benchmark</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JMH benchmark sample: Java</name>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cdk</groupId>
<artifactId>cdk</artifactId>
<version>1.5.13</version>
<scope>system</scope>
<systemPath>${cdk.lib}/cdk-1.5.13 .jar</systemPath>
</dependency>
<dependency>
<groupId>net.sourceforge.streamsupport</groupId>
<artifactId>streamsupport</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk-io</artifactId>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk</artifactId>
<version>1.5.13</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk-core</artifactId>
<version>1.5.13</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<jmh.version>1.6.3</jmh.version>
<javac.target>1.8</javac.target>
<uberjar.name>benchmarks</uberjar.name>
<cdk.lib>${basedir}/libs</cdk.lib>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>${javac.target}</compilerVersion>
<source>${javac.target}</source>
<target>${javac.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
</plugins>
</pluginManagement>
</build>

Add to file MANIFEST.MF this line:
Class-Path: lib/cdk-1.5.13.jar
Or run you benchmark thought class with main method:
java -cp path/to/cdk/lib/cdk-1.5.13.jar:. com.your.main.ClassName
For more info read answers from this discussion.
And also this answer to understand system scope of Maven dependency that you've chose for cdk-1.5.13.jar.

Related

Java classpath build with "spring-boot-maven-plugin" does not work

Try to build a classpath with jars to invoke my program with java-command
"java -cp %classpath% %mainclass%".
But can't manage to get to it run.
When building the jar with "spring-boot-maven-plugin" I always get an error because mainclass cannot be found.
When building the jar with "maven-jar-plugin/maven-assembly-plugin", the Spring environment is not found.
I have setup a small sample project to test and show. It would be great if someone could give me some help here.
My project looks like this:
mysample-base (has a packaging of "pom" and has module "mysample-frontend")
mysample-frontend (has a packaging of "pom" and has module "mysample-frontend-programs")
mysample-frontend-programs (has a packaging of "jar" and contains the programs).
These are the poms:
mysample-base/pom.xml
<groupId>com.mysamples</groupId>
<artifactId>mySamples-base</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<revision>1.0.0</revision>
<targetJarDir>E:/$SysProg/mySample/RUN/lib</targetJarDir>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<modules>
<module>mySamples-frontend</module>
</modules>
<dependencies>
<!-- ***************************************************************************************************
* Springboot *************************************************************************************************** -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- ***************************************************************************************************
* Database Access *************************************************************************************************** -->
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/jaxb2-maven-plugin -->
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${targetJarDir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
mysample-frontend/pom.xml
<artifactId>mySamples-frontend</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-base</artifactId>
<version>1.0.0</version>
</parent>
<modules>
<module>mySamples-frontend-programs</module>
</modules>
mysample-frontend-progams/pom.xml - with "spring-boot-maven-plugin"
<artifactId>mySamples-frontend-programs</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-frontend</artifactId>
<version>1.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>com.mysamples.calling.MainCalling</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
mysample-frontend-progams/pom.xml - with "maven-assembly-plugin"
<artifactId>mySamples-frontend-programs</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-frontend</artifactId>
<version>1.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifestEntries>
<Build-Version>${project.version}</Build-Version>
<Built-By>${user.name}</Built-By>
<Build-Jdk>${java.version}</Build-Jdk>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Build-Number>${buildNumber.value}</Build-Number>
<Build-YearStarted>2020</Build-YearStarted>
<DeveloperName>Ulrich Schmidt</DeveloperName>
</manifestEntries>
</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>
I' m running this command:
cd /D .....
SET CLASSPATH=mySamples-frontend-programs-1.0.0.jar
java -Duser.language=en -cp mySamples-frontend-programs-1.0.0.jar com.mysamples.calling.MainCalling
In case of using "spring-boot-maven-plugin" for building jar, I get this message:
Error: Could not find or load main class com.mysamples.calling.MainCalling
Looking in the jar file shows, that the main-class is stored to "ROOT-INF/classes". In the root-path of the jar I can only find the spring framework.
In case of using "maven-assembly-plugin" for building jar, I get this message:
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:467)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:180)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:123)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:434)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.mysamples.calling.MainCalling.main(MainCalling.java:27)
The both of the classes created are:
#ComponentScan({"com.mysamples"})
#SpringBootApplication
public class MainCalling {
private static final Logger LOGGER = LoggerFactory.getLogger(MainCalling.class);
#Autowired
public MainCalling(final ClassToBeCalled toBeCalled) {
toBeCalled.isCalled();
}
public static void main(String[] args) {
try {
SpringApplication.run(MainCalling.class);
} catch (Exception e) {
LOGGER.error("", e);
System.exit(-1);
}
}
and
#Service
public class ClassToBeCalled {
private static final Logger LOGGER = LoggerFactory.getLogger(ClassToBeCalled.class);
public void isCalled() {
LOGGER.info("have been called");
}
}
I think I got it. "spring-boot-maven-plugin" does not allow for the command "java -cp ${classpath} ${chosenMain}". You have to use "java -jar ${classpath}" - the way the jar is created, by only springframework in the rootDir of the jar does not nable for calling directly the designated mainClass. The way how to invoke multiple main-Classes is described in "Running spring boot with multiple main classes"
Thanks to #khmarbaise for the hint. Couldn't believe in the first place, but after some reading, I got, he is right.

How to do I start a Spring Boot service before the Serenity integration tests?

I googled a lot but I didn't find a proper solution to my question. So maybe here.
There is a Spring Boot service that I would like to test through REST API in build time. So the service needs to be executed as a standalone service in the build phase before the integration tests are executed.
I can execute somehow it but not the ideal.
I did something similar that the this article
I have a maven project with this 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>
<groupId>my.project.package</groupId>
<artifactId>my-project-name</artifactId>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>my-project-name</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<parallel.tests>3</parallel.tests>
<serenity.maven.version>2.0.48</serenity.maven.version>
<cucumber.version>4.8.0</cucumber.version>
<serenity.version>2.1.2</serenity.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16-beta1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber4</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-spring</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>**/*Runner.java</include>
</includes>
<parallel>classes</parallel>
<threadCount>${parallel.tests}</threadCount>
<forkCount>${parallel.tests}</forkCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I made an entry point for the test execution:
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
features = "src/it/resources/features",
glue = "my.project.package.integrationtest",
plugin = {
"pretty"
},
tags = "(not #Ignore) or (not #Manual) or (not #ToBeImplemented)"
)
#ActiveProfiles("integration-test")
public class IntegrationTestRunner {}
I have a StepsBase class which starts the app:
#RunWith(SpringRunner.class)
#SpringBootTest(webEnvironment = RANDOM_PORT)
#ActiveProfiles("integration-test")
#ContextConfiguration(classes = Application.class)
public class StepsBase {
public static final String HOST = "http://localhost:";
#LocalServerPort
private int serverPort;
public String getBaseUrl() {
return HOST + serverPort;
}
}
And all my steps classes extends the StepsBase class like this
public class SimpleSteps extends StepsBase {
#Given("this is a sample step")
.
.
.
}
If I execute the service build with maven clean verify, then I get the following log for the integration tests:
The main problem with this solution is the first scenario execute the Spring Boot service before instantiating the step class, which is counting into the execution time, and the test cases are not compromised if the service is not starting. Bytheway the Serenity before every scenario checks that the service is running or not.
Do you have an idea of how to make that the service is started before Serenity startup?
Or before the first step execution?
If everything is in the same project (or maven module) you can use the Spring Boot Maven plugin (https://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html). A sample configuration is shown below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.4.RELEASE</version>
<configuration>
<classifier>exec</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
```

Compile errors due to missing queryDSL classes when creating arquillian webArchive with shrinkwrap and MavenImporter

I'm trying to write a simple arquillian test to a large project. There are a bunch of QClasses that are automatically created to query the database but it seems that at the time Shrinkwrap.create() runs, those classes are not created yet and the deploy never completes.
MyTest class:
package pkg.integration.service;
import static org.junit.Assert.assertNotNull;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter;
import org.junit.Test;
import org.junit.runner.RunWith;
import pkg.service.TestService;
#RunWith(Arquillian.class)
public class MyTest {
#Deployment
public static WebArchive getDeploy() {
return ShrinkWrap.create(MavenImporter.class)
.loadPomFromFile("/path/to/pom.xml")
.importBuildOutput()
.as(WebArchive.class);
}
#Inject
private TestService testService;
#Test
public void test() {
assertNotNull(testService);
}
}
Execution stacktrace:
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive br.com.company.integration.service.MyTest.getDeploy()
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:181)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:103)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:64)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:92)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:92)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:202)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:431)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:55)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:219)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:167)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)
... 49 more
[omitted]
symbol: class QConfiguracao
location: package com.company.portal.model, /path/to/src/main/java/pkg/portal/service/UserService.java:[124,38] cannot find symbol
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
location: package pkg.vo
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.AbstractCompilingProcessor.constructCompilationException(AbstractCompilingProcessor.java:120)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.AbstractCompilingProcessor.compile(AbstractCompilingProcessor.java:92)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.WarPackagingProcessor.importBuildOutput(WarPackagingProcessor.java:84)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.WarPackagingProcessor.importBuildOutput(WarPackagingProcessor.java:50)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.PomEquippedMavenImporterImpl.importBuildOutput(PomEquippedMavenImporterImpl.java:49)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.PomEquippedMavenImporterImpl.importBuildOutput(PomEquippedMavenImporterImpl.java:44)
at pkg.service.MyTest.getDeploy(MyTest.java:27)
... 54 more
Test ignored.
jun 16, 2017 8:32:38 PM org.jboss.arquillian.core.impl.ObserverImpl resolveArguments
ADVERTÊNCIA: Argument 2 for ArquillianServiceDeployer.undeploy is null. It won't be invoked.
Process finished with exit code 255
build>:
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.sql</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/db</directory>
<targetPath>db</targetPath>
<filtering>false</filtering>
</resource>
</resources>
<filters>
<filter>${basedir}/src/main/resources/filters/${filter.name}.properties</filter>
[filters...]
</filters>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<extensions>false</extensions>
</plugin>
<!-- Compila .jrxml para .jasper -->
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<dependencies>
<!--Força para ser as mesmas versões de runtime-->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>${jasperreports-fonts.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- mvn backupdb:copy backupdb:restore -->
<plugin>
<groupId>com.company</groupId>
<artifactId>backupdb-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<databaseType>postgres</databaseType>
<bucketFolder>${company.db.name}/db</bucketFolder>
<databaseName>${company.db.name}</databaseName>
<postScript>src/test/resources/db/post_restore.sql</postScript>
</configuration>
</plugin>
<plugin>
<groupId>com.company</groupId>
<artifactId>company-jpa-maven-plugin</artifactId>
<version>${company.jpa.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<includes>
<include>**/*Spec.java</include> <!-- Yes, .java extension -->
<include>**/*Test.java</include> <!-- Just in case of having also "normal" JUnit tests -->
</includes>
<argLine>-Xmx256m</argLine>
<properties>
<property>
<name>listener</name>
<value>com.company.testng.ListenerDominio</value>
</property>
</properties>
<threadCount>1</threadCount>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
<configuration>
<testSources>
<testSource>
<directory>${project.basedir}/src/test/java</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<versionRange>[1.0-beta-2,)</versionRange>
<goals>
<goal>compile-reports</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<!-- we want to execute specifications -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
<includes>
<include>**/*Specification*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>arquillian-wildfly-remote</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- this is required to get test resources filtered properly -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
dependencyManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>${version.org.jboss.shrinkwrap.resolver}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-bom</artifactId>
<version>${version.org.jboss.shrinkwrap}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-core</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-standalone</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.spock</groupId>
<artifactId>arquillian-spock-container</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>company-external-bom</artifactId>
<version>2.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>company-parent-test</artifactId>
<version>1.0.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
So... What am I'm missing?
PS: I'm executing the tests through Intellij. A mvn clean package on terminal gives me a:
[ERROR] /path/to/src/test/java/company/service/MyTest.java:[8,33] error: package org.jboss.arquillian.junit does not exist
[ERROR] /path/to/src/test/java/company/service/MyTest.java:[16,9] error: cannot find symbol
IIRC Maven runner does not honor all plugins but just the common ones. I think that in you case you should use EmbeddedMaven https://github.com/shrinkwrap/resolver#embedded-maven instead of importer.
Yeah, the MavenImporter is probably not the best solution for you - it takes your dependency stack, compiles all classes in src/main/java directory, takes all resources and merges everything in the resulting web-archive. It doesn't take into account any plugin that you use nor additional directories.
On the other hand, EmbeddedMaven builds the whole project, so then you can use an archive that contains all necessary classes/dependencies.
As for the error: package org.jboss.arquillian.junit does not exist it seems that you don't have correct dependencies on your classpath. Please share your <dependencies> you have in your pom.xml file or your dependency tree.

Before Aspect not executed

I'm new to Spring AOP and trying to configure an Aspect to be executed before any method of my controller classes. I'm using Java 8 and using aspectJ-maven-plugin to weave code.
In my pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>${io.spring.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</dependency>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>usermgmt</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<encoding>UTF-8</encoding>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<Xlint>warning</Xlint>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
And in my spring context file I've enabled
<aop:aspectj-autoproxy />
My Aspect class looks like below :-
#Component
#Aspect
public class MyAspecct{
#Before("execution(* com.abc.web.controller.*.*(..))")
public void validateAuthToken(JoinPoint jointPoint){
// do something
}
Despite of having all these configuration the Aspect is not invoked before any controller methods.
Can someone please suggest where the problem is. Thanks in advance.

Is it possible to make JSF FacesServlet work with AspectJ?

I'm trying to write sample application showing the intergration between JSF's FacesServlet running on tomcat and AspectJ. I've created two projects:
1) JSF project:
pom.xml:
<dependencies>
<!-- JSF 2.0 dependencies -->
<dependency>
<groupId>com.pac</groupId>
<artifactId>aspectj-lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>JavaServerFaces</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.pac</groupId>
<artifactId>aspectj-lib</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
ManagedBean:
#ManagedBean
#SessionScoped
public class HelloBean implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
test();
return name;
}
public void setName(String name) {
test();
this.name = name;
}
public int test(){
System.out.println("Test is invoked");
return 10;
}
}
2) aspectj-lib which contains all aspects
pom.xml:
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
TestAspect.aj:
public aspect TestAspect {
pointcut t(): execution(public !static * *(..));
int around() : t() {
System.out.println("Test string");
int v = proceed();
return v * 2;
}
}
So, I expected the aspect should have come into play when test() was being called. But it didn't, all I saw in the console's output was:
Test is invoked
Test is invoked
Test is invoked
Test is invoked
Test string defined in the aspect was not being printed.
How can I integrate JSF and AspectJ? Is there a documentation?
Maybe I should add additional confiduration information in web.xml/faces-config.xml or create another config file to make it work?
Documentation reference
The answer was quite simple. All we had to do was to replace compile-time weaving with load-time weaving. Load-time weaving means that we're going to weave our classes when JVM tries to load their. Replace is neccesary, beacause compile-time weaving and load-time weaving are not compatible with each other. So, assume we have two projects:
aspects-lib
|---pom.xml
|---src/main/aspect
|---TestAspect.aj -- aspect itself
JavaServerFaces
|---pom.xml
|---src/main/java
| |---TestBean.java -- The bean which methods we want to intercept
|---src/main/resources
| |---META-INF/aop.xml -- That file configures the load-time weaving
|---src/main/webapp
|
webpages, omited
Let's consider the configuration now.
aop.xml (load-time weaving configuration):
<aspectj>
<aspects>
<aspect name="fully.qualified.ascpect.name"/>
</aspects>
<weaver options="-verbose">
<include within="package.you.want.to.weave.*"/>
</weaver>
</aspectj>
aspect-lib/pom.xml:
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<!-- IMPORTANT!!!!!! -->
<!-- DISABLING COMPILE TIME WEAVING -->
<outxml>true</outxml>
<XterminateAfterCompilation>true</XterminateAfterCompilation>
<!-- DISABLING COMPILE TIME WEAVING -->
</configuration>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
JavaServerFaces/pom.xml:
<dependency>
<!-- aspect-lib dependency -->
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<outxml>true</outxml>
<XterminateAfterCompilation>true</XterminateAfterCompilation>
<aspectLibraries>
<aspectLibrary>
<!-- your aspect lib -->
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
And one more thing: You should add the following option to the JVM in order to allow your servlet-container/app-server perfrom load-time weaving:
-javaagent:pathto/aspectjweaver.jar
The corresponding jar-file should be added to server's resources.

Resources