I am trying to generate enunciate documentation form a mix of classes, all JAX-RS annotated, some coded inn java, some in clojure.
I have built a maven project that simply depends on a war file containing the service classes:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-plugin</artifactId>
<version>1.27</version>
<configuration>
<configFile>src/conf/enunciate.xml</configFile>
<additionalClasspathEntries>
${settings.localRepository}/com/ws/scholar/0.96-SNAPSHOT/scholar-0.96-SNAPSHOT.war
</additionalClasspathEntries>
</configuration>
<executions>
<execution>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.ws</groupId>
<artifactId>scholar</artifactId>
<version>0.96-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
I cannot get any service documentation to generate.
When running mvn enunciate:docs -X, I see my classes "Noticed":
[DEBUG] Noticed class WEB-INF.classes.com.ws.scholar.resources.ClientResource in /.m2/repository/com/ws/scholar/0.96-SNAPSHOT/scholar-0.96-SNAPSHOT.war.
Can anyone offer guidance or corrections to my configuration?
Unfortunately, you can't just add a war as a dependency and have the classes therein get picked up on the classpath. A war isn't a jar.
Instead, you'll probably need to use the attachClasses parameter of the maven-war-plugin to export your classes as a jar in addition to the war. Then you can depend on that jar like this:
<dependency>
<groupId>com.ws</groupId>
<artifactId>scholar</artifactId>
<version>0.96-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
Related
I am using Powermock but when I run Eclemma coverage, the Powermock test cases are not considered in the final score because of known issues with EclEmma.
The work around for this which I search and other answers on stackoverflow suggest to have:
#Rule
public PowerMockRule rule = new PowerMockRule();
static {
PowerMockAgent.initializeIfNeeded();
}
Then add jars like powermock-module-javaagent, powermock-module-junit4-rule-agent.
After doing this when I am running my code then finding error:
java.lang.VerifyError: Expecting a stackmap frame at branch target 7
For this answers suggest to have javassit of various versions. But I am unable to get that work and getting the same error.
My pom.xml looks like:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-javaagent</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule-agent</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.21.0-GA</version>
<scope>test</scope>
</dependency>
How can I get PowerMock test cases to be included in final Eclemma score ?
My favorite non-answer: don't waste your time trying.
Instead, take this as another hint that PowerMock should not be used; and use your time and energy to learn how to write better production code that can be tested without the need to PowerMock.
For example, start looking into those videos; to understand that code that avoids calls to static or new (in an untestable) way is very often bad code; and that improving this code not only helps you to get rid of PowerMock, but also to improve your over all product.
And in case you find leaving PowerMock to hard; my suggestion: then put your tests into two buckets (one for those that really use PowerMock for things only PowerMock can do; and one for all others); and only measure coverage for the later one. This would also open a "path forward": simply avoid using PowerMock for any new things you. Instead, you could turn to mockito, which has improved a lot of the last years; even allowing you things (experimentally) like overriding final methods.
I figured out a way, may be not clean but I think it works out. So the problem statement was how to get Powermock get included in EclEmma ?.The first change in approach was move to maven approach of Eclemma i.e. jacoco Please feel free to go through the link below before moving to the answer:
Power mock with jacoco
Basic of Java Instrumentation
In a nutshell, jacoco identifies code coverage by having a lock/updating bytecode/instrumenting the class, when being loaded. And powermock for its working also lock/updates bytecode/instrumenting the class for its functioning, BUT IT DOES THIS FROM THE DISK AND NOT THE MEMORY.
Thus when coverage is given by jacoco, powermock classes are not covered as powermock runs test cases from disk files and jacoco has no idea what powermock is doing.
So the work around it to store the classes instrumented by jacoco on the disk and then powermock runs test through those classes which in turn will let jacoco know that test are running and include them in code coverage.
[PLS FEEL FREE TO CORRECT MY UNDERSTANDING REGARDING THIS]
So the final code changes are:
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.7.7.201606060606</version>
<classifier>runtime</classifier>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.1</version>
<scope>test</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
// files you want to exclude
</excludes>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/coverage.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
after this running -PcodeCoverage worked out for me.
I am using Apache Axis to generate the java source from my WSDL file. The maven run was successful without any errors but no generated classes.
Question: What am I missing here?
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceDirectory>/src/main/resources</sourceDirectory>
<outputDirectory>/src/main/java</outputDirectory>
<wsdlFiles>
<wsdlFile>thesourcewsdlfile.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
I am clearly not sure what is the problem with this configuration.
Try to define source and output directory bases on your maven project, that is, using standard maven properties to point to the right absolute path at runtime, changing your configuration as following:
<sourceDirectory>${basedir}/src/main/resources</sourceDirectory>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
Based on this configuration, the thesourcewsdlfile.wsdl is supposed to be located under src/main/resources/thesourcewsdlfile.wsdl
The full plugin configuration should hence be:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/resources</sourceDirectory>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<wsdlFiles>
<wsdlFile>thesourcewsdlfile.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Moreover, the following dependencies must be added to the project:
<dependencies>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
As a general note, it would be much better to place generated sources under the target directory, since they are generated automatically and should not be added to the version control in use. A standard location would then be any desired (meaningful) directory under ${project.build.directory}/generated-sources (where ${project.build.directory} is the standard property pointing to the target directory indeed).
IMHO you are missing the wsdl folder under resources, just add it and run:
mvn clean generate-sources
Error like this:- java.lang.ClassNotFoundException:
com.sun.jersey.spi.container.servlet.ServletContainer at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at
org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
It will work when I put all jar files under lib (WEB-INF/lib) folder.But I want pom file to solve this.
It's all about your configuration resp. pom.xml and incomplete tutorials. If you want your pom.xml to solve this for you, you need to add a few things.
Plugins
First things first. The little red cross and the fact, that your project is configured to run under Java 1.5 lets me guess, that you have compatibility issues with your deps. Especialy with javax.ws.rs \ javax.ws.rs-api.
To solve this, you may want maven handle it by the maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Then, you possibly want to run the server "in" eclipse. Here you can use the tomcat7-maven-plugin:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
The last plugin to use is the maven-war-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Jersey Dependencies
To start with Jersey you just need to configure a single dep:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
I need to say, that there are newer versions available, but you might have reasons to use 1.19
Your complete pom.xml should now look like:
<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>sujith</groupId>
<artifactId>jersey-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.maven-compiler-plugin.version>3.5.1</project.maven-compiler-plugin.version>
<project.tomcat7-maven-plugin.version>2.2</project.tomcat7-maven-plugin.version>
<project.maven-war-plugin.version>2.6</project.maven-war-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<outputDirectory>${project.artifactId}</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${project.maven-compiler-plugin.version}</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${project.tomcat7-maven-plugin.version}</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${project.maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
In Eclipse you now right click your project and select -> Run As / Debug As -> Maven build...
In the Edit configuration and lauch menu, you now add the goal: clean install tomcat7:run-war and that's it.
Your server should start and the resource is available under http://127.0.0.1:8080 / {web.xml\servlet-mapping\url-pattern} / {path-to-resource}
One last thing. Please check out the original examples first. Most of the tutorial out there are crap. And finally, pls read the how to ask pages.
Have a nice day.
We are using Soap-UI for writing some web-services tests.
I put this XPath validation in one of them:
count(//mynode) > 1
This is working fine while executing from SOAP-UI software, but when the continuous integration (jenkins) execute it through the Maven Soap-UI plugin, I receive this error:
[XPath Match] junit/framework/ComparisonFailure
I guess there is a missing library somewhere but cannot figure what to do.
What is strange is that I do not refers any jUnit tests as I just call URL's of web-services.
Finally I found that there is a junit dependency to add with the help of this thread
Here is the dependency I had to add in my pom.xml file:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
For the maven-soapui-plugin.
The whole config will looks like:
<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>4.0.1</version>
<executions>
<execution>
<id>services-customer</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<projectFile>services/customer/smoke-tests.xml</projectFile>
<projectProperties>
<value>IdmpDataEndPointHost=${smoke.dataload.url}</value>
<value>WebServiceEndPointHost=http://${smoke.tomcat.server}:${smoke.tomcat.port}</value>
</projectProperties>
<outputFolder>${project.build.directory}/soapui-results/services/customer</outputFolder>
<junitReport>true</junitReport>
<testFailIgnore>true</testFailIgnore>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
</plugin>
One of my projects needs a pretty complex setup for the resulting JAR file, so I'd like to run a test after the package phase to make sure the JAR contains what it should.
How do I do that with Maven 2?
You can use the surefire-plugin for this. what you need to do is associate a phase with an execution (see below). You will need to change the phase to be whatever you want it to be in your case one after the package phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>unittests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/**/**/*Test.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Convert your project into a multi-module build. In the first module, build your original project. In the second module, add a dependency to the first.
This will add the first JAR to the classpath.
Update by OP: This works but I had to add this to my POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.maven-surefire-plugin}</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
The important part is <useSystemClassLoader>false</useSystemClassLoader>. Without this, my classpath only contained a couple of VM JARs plus the surefire bootstrap JAR (which contains the test classpath in the MANIFEST.MF). I have no idea why this test classpath isn't visible from the classes loaded from it.