I'd like to start a new local Tomcat instance for testing purposes during the Maven's pre-integration-test phase (on different port) and run tests there. Then if the tests pass I'd like to do a cargo:redeploy to a remote Tomcat instance. I'm having issues with getting this right though. If I do
mvn org.codehaus.cargo:cargo-maven2-plugin:run -Dcargo.maven.containerId=tomcat8x -Dcargo.maven.containerUrl=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.zip -Dcargo.maven.type=standalone
I get
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.19:run (default-cli) on project atf-relay-server: Execution default-cli of goal org.co
dehaus.cargo:cargo-maven2-plugin:1.4.19:run failed: Cannot create configuration. There's no registered configuration for the parameters (container [id = [tomcat
8x], type = [installed]], configuration type [runtime]). Valid types for this configuration are:
[ERROR] - standalone
[ERROR] - existing
[ERROR] -> [Help 1]
My pom.xml for cargo is (specifying only remote instance):
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.19</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>localhost</cargo.hostname>
<cargo.servlet.port>9990</cargo.servlet.port>
<cargo.remote.username>user</cargo.remote.username>
<cargo.remote.password>pass</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
</deployer>
</configuration>
</plugin>
What's the correct way to achieve this?
Ok, seems it's quite easy to achieve after getting familiar with Maven profiles.
I have now one profile controlling remote Tomcat instance and doing the cargo:redeploy and other profile just creating local Tomcat, running it, deploying app there and running the tests.
Related
We working in small team of 4 people. We using docker to deploy our services. One of the services is a java Spring Boot project which is deployed after building docker image with maven. To make docker image of Spring Boot service we use mvn clean package dockerfile:build.
The fun part is that my colleagues have no problem building docker image of Spring Boot service. And I get maven error message:
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.6:build (default-cli) on project 'foo': Could not build image: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.client.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('osxkeychain')
I tried to remove all maven repositories from .m2/repository, restart docker, and remove all images.
Later I tried to run mvn clean package dockerfile:build in to two separate commands:
mvn package, then
mvn docker:build
mvn package passed, and mvn docker:build failed with the same error as shown above.
Maven version 3.5.4,
Docker version 18.06.1-ce, build e68fc7a,
OS: macOS mojave
I even tried to restart my PC hoping that it will fix it...
Edited:
Here is the maven pom plugin dockerfile-maven-plugin
...
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${project.artifactId}</repository>
</configuration>
</plugin>
...
Edit 2:
Full error message:
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.6:build (default) on project spring-boot-service: Could not build image: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.client.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('swarm')
[ERROR] at [Source: N/A; line: -1, column: -1] (through reference chain: java.util.LinkedHashMap["stackOrchestrator"])
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Edit 3:
docker-compose.yml
wrapper:
image: spring-boot-service:latest
ports:
- "8080:8080"
expose:
- "8080"
links:
- db
- another-service
Solved:
In my case it was wrong version of dockerfile-maven-plugin. I used 1.3.6, and 1.4.7 fixed the problem.
Thanks to Boris!
Update: One more thing!
Make sure when mvn finish build naming is correct, for example:
[INFO] Successfully built **spring-boot-service:0.0.1-SNAPSHOT**
And docker-compose.yml should look like this:
...
wrapper:
image: **spring-boot-service:0.0.1-SNAPSHOT**
...
Here is the dockerfile-maven-plugin config:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-plugin.version}</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
NOTE: use the latest released version 1.4.7
This configures the plugin to build and push your image with a single command:
$ mvn clean deploy
If you only want to build the Docker image, run:
$ mvn clean package
Solution:
Go to docker desktop
Open settings
Go to general and put tick on Expose daemon on tcp://localhost:2375 without TLS
enter image description here
After adding module-info.java files to my project my checkstyle plugin start failing with:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project email: Failed during checkstyle
configuration: NoViableAltException occurred during the analysis of
file
/home/xxx/IdeaProjects/blynk-server/server/notifications/email/src/main/java/module-info.java.
unexpected token: module -> [Help 1]
I tried
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
However, it failed with:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project blynk: Failed during checkstyle
configuration: cannot initialize module
BeforeExecutionExclusionFileFilter - Unable to instantiate
'BeforeExecutionExclusionFileFilter' class, it is also not possible to
instantiate it as
com.puppycrawl.tools.checkstyle.checks.annotation.BeforeExecutionExclusionFileFilter
What is the correct way for skipping module-info.java files during checkstyle for maven-checkstyle-plugin?
Not sure why the Checkstyle filter is not working (this reported bug seems very similar to yours and it was fixed in version 7.3.0, so maybe you need to update Checkstyle).
Anyway the Maven excludes element is also supposed to do this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<excludes>**/module-info.java</excludes>
</configuration>
</plugin>
More in the plugin goal documentation.
BeforeExecutionExclusionFileFilter was added in Checkstyle 7.2.
But the maven-checkstyle-plugin version 3.0.0 (which is the latest version as of 2018-04-01) uses Checkstyle 6.18 by default.
"Checkstyle" and "Checkstyle Maven Plugin" are different things and have different release cycles.
You may want to upgrade the Checkstyle version as follows:
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version> <!-- Checkstyle Plugin version -->
<!-- ... Configuration, Executions ... -->
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.8</version> <!-- Checkstyle version -->
</dependency>
</dependencies>
</plugin>
After that, BeforeExecutionExclusionFileFilter as well as other newer Checkstyle features (e.g. new checks) will be recognized.
Though this doesn't possibly qualify as an answer. Yet being too long to fit in comment, just to keep a note of the track that the maven-checkstyle-plugin is in:-
The last release of the was version 2.17 on 15-Oct-2015 which was almost 2 years back.
The current trunk of maven-plugins points to an ongoing work within the plugin in its 3.0.0-SNAPSHOT version which might mean we can soon expect a org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0 sometime in near future and which would understand the module-info.java as a class.
This doesn't align with the Java+9+-+Jigsaw doc that specifies the list of modules and plugins that are being upgraded to support JDK-9.
I am having the below issue when I run my maven build in eclipse. I saw many posts like this but i still can't solve this problem .Mine may be a little more specific, I know that my JAVA_HOME is pointed to java6, and that is because I am working on another application which uses java 6. The application in which I am running into issues uses Java 8
[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in: C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). .In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable. [INFO] 1 error
<br>[INFO] -------------------------------------------------------------
<br>[INFO] ------------------------------------------------------------------------
<br>[INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------
<br>[INFO] Total time: 11:53 min [INFO] Finished at: 2016-08-18T16:52:13+05:30
<br>[INFO] Final Memory: 11M/141M
<br>[INFO] ------------------------------------------------------------------------
<br>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project
Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and [ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
<br>[ERROR] In most cases you can change the location of your Java [ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
How can I resolve this problem without installing java 8 as it may may make changes to my JAVA_HOME etc which would make my other application to not run. Is there a way to get the JDK folder without running the .exe (p.s I already tried the 7zip method)
Please suggest
If you have the jdk8 then you can open cmd, run the command in this window to modify the JAVA_HOME set JAVA_HOME=<jdk8 path>. This will modify the JAVA_HOME env variable only for this instance of the cmd session and not for the whole OS. Now run the maven build command from this window and it wont fail.
If you wanna run the build from eclipse, then in eclipse try going to Windows --> Preferences --> Java --> Installed JREs --> click Add button --> Sel Standard VM and click next --> put in values for 'JRE Home' as path till the jdk folder and 'JRE Name' as java8 or whatever you wish --> click Finish.
Now right click the project of you interest --> click properties --> Java Compiler --> Tick 'Enable project specific settings' --> and select 1.8 here.
If 1.8 is not visible here, go to Java Build Path --> Add Library --> JRE System Library --> Alternate JRE --> select jdk8 --> Finish
Looking at the path in that error (C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar) you've installed the Java Runtime Environment (JRE).
To compile java you need the Java Development Kit (JDK) which contains the tools the maven plugin needs.
You can change your maven-compiler-plugin configurations to your JAVA_HOME.
Just go to eclipse window->preferences->type maven->and you could see something like template click on that and look for javac compiler, just go there and change to whatever java version you have.
<configuration>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>${cursor}1.6</source>
<target>1.6</target>
</configuration>
Without java8 and without .exe file you can't go ahead with your requirement.
Hope it's useful.
from your error log it says that
[ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar
paste this code in your pom.xml inside build tag and make sure you add dependencies properly and please change your java version accordingly
this will only work if you have something wrong in your pom.xml.
<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>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<jvm>${JAVA_HOME}/bin/java</jvm>
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
note your JAVA_HOME must point like this
C:\Program Files\Java\jdk1.8.0_65
edit
There must be various reasons like
your pom is not getting path to java home
your java home is not set
you are using jre instead of jdk in your IDE
You can download the version of the JDK without installer.
Then specify a JDK 1.8 as source and target in the compiler configuration of the pom.xml with which you have your problem. in this way you don't need changing your JAVA_HOME :
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
<fork>true</fork>
<executable>D:\jdk1.8\bin\javac</executable>
</configuration>
</plugin>
<build>
I followed steps in the below link to get the portable JDK:
http://bgasparotto.com/convert-jdk-exe-zip/
While running mvn install on a fragment project in Eclipse I got this error:
${fragment name} cannot be installed in this environment because its filter is not applicable.
Using Eclipse-PlatformFilter: (osgi.os=macosx) in the Manifest breaks the build.
Here's the output surrounding the key error (IDs/directory names redacted):
[INFO] Resolving dependencies of MavenProject: ${fragmentID}:4.3.0-SNAPSHOT # ${fragmentDir}/pom.xml
[INFO] {osgi.os=linux, org.eclipse.update.install.features=true, osgi.arch=x86_64, osgi.ws=gtk}
[ERROR] Cannot resolve project dependencies:
[ERROR] Problems resolving provisioning plan.:
[ERROR] ${fragment name} cannot be installed in this environment because its filter is not applicable.
[ERROR]
[ERROR] See http://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting for help.
The link (http://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting) doesn't help.
I found a few similar errors on the internet (component X cannot be installed in this environment because its filter is not applicable), but they all apply to instances where it's downloaded software and there's either no solution or the solution isn't applicable to my case.
Grateful for any help!
Edit:
I found that using Eclipse-PlatformFilter: (osgi.os=macosx) in the host plugin works, and also Eclipse-PlatformFilter: (| (osgi.os=macosx) (osgi.os=linux) (osgi.os=win32) ) in the fragment works. It seems that the build goes through each environment set in an ancestor pom, and it breaks when the fragment doesn't apply for any one of those environments.... surely there's some flag I could set to prevent that?
Tycho builds for all the operating system environments configured through the POM. There is currently no way to automatically filter these environments to what is configured as Eclipse-PlatformFilter. So when building a fragment only for a certain operating system, you need to manually override the <environments> configuration from your parent POM in the POM of the fragment:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<environments>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
When I run maven test, java.lang.OutOfMemoryError happens. I googled it for solutions and have tried to export MAVEN_OPTS=-Xmx1024m, but it did not work.
Anyone know other solutions for this problem? I am using maven 3.0
Paste the error message here when run mvn test -e
Failed tests:
warning(junit.framework.TestSuite$1)
testDefaultPigJob_1(com.snda.dw.pig.impl.DefaultPigJobLocalTest)
testDefaultPigJob_2(com.snda.dw.pig.impl.DefaultPigJobLocalTest)
Tests run: 11, Failures: 3, Errors: 0, Skipped: 0
10/11/01 13:37:18 INFO executionengine.HExecutionEngine: Connecting to hadoop fi
le system at: file:///
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.063s
[INFO] Finished at: Mon Nov 01 13:37:18 PDT 2010
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
5:test (default-test) on project dw.pig: There are test failures.
[ERROR]
[ERROR] Please refer to E:\Code\Java\workspace\dw.pig\target\surefire-reports fo
r the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project
dw.pig: There are test failures.
Please refer to E:\Code\Java\workspace\dw.pig\target\surefire-reports for the in
dividual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:199)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:148)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:140)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:314)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:151)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures
.
Please refer to E:\Code\Java\workspace\dw.pig\target\surefire-reports for the in
dividual test results.
at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugi
n.java:629)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:195)
... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
When I run maven test, java.lang.OutOfMemoryError happens. I google it for solutions and have tried to export MAVEN_OPTS=-Xmx1024m, but it did not work.
Setting the Xmx options using MAVEN_OPTS does work, it does configure the JVM used to start Maven. That being said, the maven-surefire-plugin forks a new JVM by default, and your MAVEN_OPTS are thus not passed.
To configure the sizing of the JVM used by the maven-surefire-plugin, you would either have to:
change the forkMode to never (which is be a not so good idea because Maven won't be isolated from the test) ~or~
use the argLine parameter (the right way):
In the later case, something like this:
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
But I have to say that I tend to agree with Stephen here, there is very likely something wrong with one of your test and I'm not sure that giving more memory is the right solution to "solve" (hide?) your problem.
References
Maven 2 Surefire Plugin
Classloading and Forking in Maven Surefire
For those new to Maven (like me) here is the whole config that goes in the build section of your pom. Cheers.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
</plugins>
</build>
The chances are that the problem is in one of the unit tests that you've asked Maven to run.
As such, fiddling with the heap size is the wrong approach. Instead, you should be looking at the unit test that has caused the OOME, and trying to figure out if it is the fault of the unit test or the code that it is testing.
Start by looking at the stack trace. If there isn't one, run mvn ... test again with the -e option.
To temporarily work around this problem, I found the following to be the quickest way:
export JAVA_TOOL_OPTIONS="-Xmx1024m -Xms1024m"
I have solved this problem on my side by 2 ways:
Adding this configuration in pom.xml
<configuration><argLine>-Xmx1024m</argLine></configuration>
Switch to used JDK 1.7 instead of 1.6
As mentioned in the top answers, as Surefire is creating a new JVM to run your tests, you want to pass that -Xmx1024m to the new JVM instead of the JVM where you start mvn test.
Just wanted to add that you can do that in your command like
mvn test -DargLine="-Xmx1024m"
It has equivalent effect with adding the JVM option to the Surefire plugin's configuration in pom.xml:
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
In order to resolve java.lang.OutOfMemoryError: Java heap space in Maven, try to configure below configuration in pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<argLine>-XX:MaxPermSize=500M</argLine>
</configuration>
</plugin>
Not only heap memory. also increase perm size to resolve that exception in maven use these variables in environment variable.
variable name: MAVEN_OPTS
variable value: -Xmx512m -XX:MaxPermSize=256m
Example :
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=500m"