I am trying to execute a shell script in a remote linux server during a maven build.
Following are code that i used for this purpose in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>server-copy</id>
<goals>
<goal>run</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<tasks>
<sshexec host="hostserver" username="user" trust="true"
password="password" failonerror="true" timeout="1200"
command="sh /pathofshellscript/test.sh"/>
</tasks>
</configuration>
</execution>
<executions>
Console output:
[INFO] Building test1 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (server-copy) # test1 ---
[INFO] Executing tasks
[sshexec] Connecting to hostserver:22
**Kerberos username [user109]:** user
**Kerberos password for user109:** password
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:02 min
[INFO] Finished at: 2017-06-19T14:06:27+05:30
[INFO] Final Memory: 9M/156M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (server-copy) on project test1: An Ant BuildException has occured: com.jcraft.jsch.JSchException: Auth fail -> [Help 1]
When i perform maven build , it ask for Kerberos username and password in console. I dont know why it ask for username and password since i have already provided in the pom.xml . Is there any thing that i am missing ?
Related
It's relativly simple:
I have a plugin goal tomcat7:run which i run directly in Eclipse m2e (the full command would be mvn tomcat7:run). But it runs too early (on process-classes it think), skipping the test phase. I want it to run after the test phase when invoked via cli.
I tried to simply change default-cli phase to be package instead of process-classes, but this doesn't work (phase does not change to package):
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
...
</configuration>
<executions>
<!-- Change phase, doesn't seem to change anything -->
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
Running a default phase like mvn package and this execution
<execution>
<id>default-run</id>
<phase>package</phase>
</execution>
instead works but is not an option, because i don't want to execute this when creating a real package (this plugin starts up an embedded tomcat server). I'm considering profiles, but i think profiles where not made for this kind of problem.
Relevant log:
[INFO] >>> tomcat7-maven-plugin:2.3-SNAPSHOT:run (default-cli) > process-classes # gmm >>>
[INFO]
[INFO] --- frontend-maven-plugin:0.0.26:gulp (gulp build) # gmm ---
...
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # gmm ---
...
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # gmm ---
...
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.3-SNAPSHOT:run (default-cli) < process-classes # gmm <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.3-SNAPSHOT:run (default-cli) # gmm ---
... (tomcat7:run log output here) ...
After formatting the previous builds set up a new server using Ubuntu 4.12 32bit with XFCE . I installed and configured the jenkins however when trying to generate some build the system returns the following error:
[INFO] --- rpm-maven-plugin:2.1-alpha-3:rpm (default) # satserver ---
**[WARNING] /bin/sh: 1: rpm: Permission denied**
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 31.745 s
[INFO] Finished at: 2015-09-02T09:02:35-03:00
[INFO] Final Memory: 33M/378M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1-alpha-3:rpm (default) on project satserver: RPM query for default vendor returned: '127' executing '/bin/sh -c rpm -E '%{_host_vendor}'' -> [Help 1]
The configuration of the maven looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-3</version>
<extensions>true</extensions>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<copyright>........
Solution
The answer from our friend Etan Reisner is correct. I installed the RPM package in Ubuntu and it worked properly. Thank you.
I use maven-source-plugin to generated java-source. However doing "mvn clean ; mvn package" does not generate a project-sources.jar in the target directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
info:
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # weibo4j ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # weibo4j ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # weibo4j ---
[INFO] Building jar: F:\step-by-step\weibo4j\target\weibo4j-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-source-plugin:2.3:jar-no-fork (attach-sources) # weibo4j ---
[INFO] No sources in project. Archive not created.
If you have your sources in a directory that maven does not consider a source directory -- such as webapp -- your files will not be put in your project-sources.jar.
Solution: signal to maven what your source directory is. Add:
<build>
<sourceDirectory>${basedir}/src/main/webapp</sourceDirectory>
</build>
I have to get the code coverage of a application while business test are executed from a different code base.
I use: Maven as my build
Jbehave as my testing framework.
The test are written in java.
My application is a set of war files deployed on tomcat.
The application code base is separate from test code base.
In getting the coverage I followed the below steps.
1 Compile the test code using maven.
2 Copy application classes from the place it was build (${app.code.dir}/target/classes) to ${test.code.dir}/target/classes
[3] Run the tests and jacoco report through maven
The mvn build: I have kept
<profile>
<id>coverage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<phase>process-resources</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<skip>false</skip>
<destFile>${basedir}/target/jacoco-coverage.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- <skip>true</skip> -->
<excludes>
<exclude>com/mytest/bdt/**</exclude><!-- test classes -->
<exclude>com/mytest/bdd/**</exclude><!-- test classes -->
</excludes>
<dataFile>${basedir}/target/jacoco-coverage.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
The jbehave test are executed using :
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>test</phase>
<configuration>
<includes>
<include>${embeddables5}</include><!-- TestSuite.java -->
</includes>
<excludes />
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>true</ignoreFailureInView>
<threads>1</threads>
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
<metaFilter>-skip *</metaFilter>
<metaFilter>+run</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
When I execute mvn mvn install -Pcoverage
The execution goes as follows.
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # test-bdd-testsuite ---
[INFO] --- jbehave-maven-plugin:3.7.5:unpack-view-resources (unpack-view-resources) # test-bdd-testsuite ---
[INFO] --- jacoco-maven-plugin:0.6.3.201306030806:prepare-agent (default-prepare-agent) # test-bdd-testsuite ---
[INFO] argLine set to -javaagent:/home/testUser/.m2/repository/org/jacoco/org.jacoco.agent/0.6.3.201306030806/org.jacoco.agent-0.6.3.201306030806-runtime.jar=destfile=/home/testUser/testProj/trunk/target/jacoco-coverage.exec
[INFO]
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) # test-bdd-testsuite ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # test-bdd-testsuite ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/testUser/testProj/trunk/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.1:testCompile (default-testCompile) # test-bdd-testsuite ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # test-bdd-testsuite ---
[INFO] No tests to run.
[INFO] Surefire report directory: /home/testUser/testProj/trunk/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- jbehave-maven-plugin:3.7.5:run-stories-as-embeddables (embeddable-stories) # test-bdd-testsuite ---
[INFO] Running stories as embeddables using embedder Embedder[ .....
.....
.....
Test execution log comes here .......
.....
.....
[INFO] Reports view generated with 1 stories (of which 0 pending) containing 25 scenarios (of which 0 pending)
[INFO] Meta filters excluded 0 stories and 24 scenarios
[WARNING] Failures in reports view: 0 scenarios failed
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) # test-bdd-testsuite ---
[INFO] Building jar: /home/testUser/testProj/trunk/target/test-bdd-testsuite-1.0.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.3.201306030806:report (default-report) # test-bdd-testsuite ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # test-bdd-testsuite ---
[INFO] Installing /home/testUser/testProj/trunk/target/test-bdd-testsuite-1.0.jar to /home/testUser/.m2/repository/com/testCode/bdd/test-bdd-testsuite/1.0/test-bdd-testsuite-1.0.jar
[INFO] Installing /home/testUser/testProj/trunk/pom.xml to /home/testUser/.m2/repository/com/testCode/bdd/test-bdd-testsuite/1.0/test-bdd-testsuite-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.134s
[INFO] Finished at: Tue Nov 26 19:18:28 IST 2013
[INFO] Final Memory: 14M/309M
[INFO] ------------------------------------------------------------------------
With this I get a coverage report generated with the application packages. But the coverage is shown as 0%
In the session link the application classes are not loaded.
Screenshots:
Can some one help me here?
I was able to resolve this as follows
Copy the application classes in to a instrumentation folder.
Start the app server (tomcat in mycase) with Java arguments
-javaagent:$WORKSPACE/target/lib/jacoco-agent-0.6.3.2.jar=includes=*,destfile=$TOMCAT_HOME/jacoco-coverage.exec,append=false
(I had the jacoco-agent jar copied in to my project at the layout)
Execute the tests (this can be automated or manual)
Stop the tomcat server (jacoco-coverage.exec is updated at this point)
Execute ant report target. pointing the updated jacoco-coverage.exec and copied application class folder.
Reference: http://car-online.fr/en/blog/fabien_duchene/2013-05-03-Java%20Code%20Coverage%20in%20Tomcat%20JSP%20applications,%20e.g.,%20WebGoat%20with%20Jacoco/
Thanks #jens-schauder for pointing me to post this as the answer.
I use the maven-properties-plugin during the initialization phase to read in a bunch of properties from a properties file.
I also have the jetty plugin configured to set a couple of the project properties - including those read in above - as system properties to jetty.
If I run the result as
mvn initialize jetty:run-war
it works.
If I just say
mvn jetty:run-war
it fails. How can I force a goal specified on the command line to run in a lifecycle that includes the initialization phase?
Following works for me. Hope this helps.
file: pom.xml
<profiles>
<profile>
<!-- mvn -Plocal -->
<id>local</id>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run-war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
If I just say mvn jetty:run-war it fails.
That's not what I'm experiencing. If you look at the documentation of the jetty:run-war goal, you'll see that it:
Invokes the execution of the lifecycle phase package prior to executing itself.
So all the phases preceding package plus the package itself are run and, consequently, the plugins bound to them. And indeed, with the following POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>q2488581</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>q2488581 Maven Webapp</name>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Running mvn jetty:run-war produces the following output:
$ mvn jetty:run-war
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building q2488581 - Maven Webapp
[INFO] task-segment: [jetty:run-war]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run-war
[INFO] [properties:read-project-properties {execution: default}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/q2488581/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] No sources to compile
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[q2488581] in [/home/pascal/Projects/stackoverflow/q2488581/target/q2488581]
[INFO] Processing war project
[INFO] Copying webapp resources[/home/pascal/Projects/stackoverflow/q2488581/src/main/webapp]
[INFO] Webapp assembled in[76 msecs]
[INFO] Building war: /home/pascal/Projects/stackoverflow/q2488581/target/q2488581.war
[INFO] [jetty:run-war {execution: default-cli}]
...
As we can see, properties:read-project-properties is invoked during the initialize phase (before process-resources to which resources:resources is bound) as expected.
In other words, I cannot reproduce your problem (or maybe you should be more specific).