I am using this simple pom.xml to generate an OSGi-bundle using the maven-bundle-plugin:
<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>de.test.osgi</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
This works as expected (that project contains a single public class that I have verified to be exported in the bundle). Now , if I add the following <configuration> to the plugin:
<configuration>
<outputDirectory>D:\Test</outputDirectory>
</configuration>
the build fails with the following error:
[INFO] --- maven-bundle-plugin:2.3.7:bundle (default-cli) # test ---
[WARNING] Bundle de.test.osgi:test:bundle:0.0.1-SNAPSHOT : Classpath is empty. Private-Package and Export-Package can only expand from the classpath when there is one
[WARNING] Bundle de.test.osgi:test:bundle:0.0.1-SNAPSHOT : Instructions in Private-Package, or -testpackages that are never used: .*
Classpath:
[ERROR] Bundle de.test.osgi:test:bundle:0.0.1-SNAPSHOT : The JAR is empty: dot
[ERROR] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.891s
[INFO] Finished at: Fri Mar 30 14:49:46 CEST 2012
[INFO] Final Memory: 8M/20M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.7:bundle (default-cli) on project test: Error(s) found in bundle configuration -> [Help 1]
Why is the classpath empty? What does the <outputDirectory> have to do with it? Is this a bug, or have I misunderstood something?
Edit
Running with debug-output reveals that the classpath is indeed identical with <outputDirectory>. By default, this is mavens target directory, so he will find the classes to include in the bundle there. If I change it, it will point to a directory that contains no classes to include. Confusingly, the documentation for the plugin says that <outputDirectory> is:
The directory for the generated bundles.
Is this a mistake?
outputDirectory is where the compiled classes have been written too - the error regarding empty classpath "dot" is due to giving maven-bundle-plugin an empty directory.
The bundle plugin writes the MANIFEST.MF to the outputDirectory location and this is also where it expects to find any other metadata (e.g. scr plugin's output) for the bundle.
Are you using the compiler plugin? If not it looks like a bug in the bundle plugin not honouring the outputDirectory when it calls the compiler (but honouring it everywhere else).
As #nobeh points out, you should be fine if ${project.build.outputDirectory} and outputDirectory point to the same location.
First i would suggest to check your bundle configuration and furthermore i would never use absolute path in particular platform dependent paths like D:\ etc. On the other hand the default in Maven is the target folder to put created output. Based on the docs there must be more configuration.
It's a wild guess, but try either D:/Test or D:\\Test.
Related
I'm using maven-dependency-plugin:copy-dependencies to copy all dependencies into target/dependency directory. My pom.xml is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
version of plugin is latest: 3.1.2 (defined in parent pom).
This definition is working fine with one exception: it copies all test dependencies into target directory, where I need only runtime dependencies required for running target jar.
I tried to exclude it usgin <excludeScope> configuration like described in the documentation:
<configuration>
<excludeScope>test</excludeScope>
</configuration>
But it makes the build failing with message:
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) # app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.006 s
[INFO] Finished at: 2021-02-15T10:32:26+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) on project app: Can't exclude Test scope, this will exclude everything. -> [Help 1]
I don't really understand why excluding the test scope will exclude everything, since without excluding test scope, the target directory contains all runtime dependencies too (along with test deps).
What could be the problem with excluding test dependencies? How to do it correctly?
PS: Please don't suggest me using assembly or other fat-jar plugins here, since I'm copying dependency jars intentionally for Docker image build optimization: one layer for dependencies, another for jar, where dependencies layer is always cached until any dependency changed:
COPY target/dependency /usr/lib/app/lib
COPY target/${JAR_FILE} /usr/lib/app/target.jar
The solution is probably in the includeScope description:
Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:
runtime scope gives runtime and compile dependencies,
compile scope gives compile, provided, and system dependencies,
test (default) scope gives all dependencies,
provided scope just gives provided dependencies,
system scope just gives system dependencies.
This means I would try with <includeScope>runtime</includeScope>.
To exclude dependencies which are under test scope is to use includeScope runtime instead of the excludeScope as the plugin documentation for test means 'everything'
EDIT: This question should absolutely not be closed. I'm NOT asking how to create an executable jar. A jar doesn't need to be executable to be run from the terminal. For example, if I have have this code:
package com.dogzilla.maven.quickstart;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World" );
}
}
...and Maven builds it, it creates quickstart-0.0.1-SNAPSHOT.jar. Which is not, ahem, 'executable'.
I can run it from the terminal quite successfully with this:
java -cp /opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar com.dogzilla.maven.quickstart.App
The problem, as I have written below, is experienced when using an external dependency. </end edit>
I have a simple Maven project in Eclipse (2020-6). It was set up by doing the following in Eclipse:
1. File -> New -> Other... Maven -> Maven Project
2. Used the maven-archetype-quickstart archetype
Group ID: com.dogzilla.maven
Artifact ID: quickstart
Right click the pom file -> select Add Dependency -> enter:
Group ID: com.google.code.gson
Artifact ID: gson
Version: 2.8.6
Which I verified on https://search.maven.org/
Here's the POM file:
<?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>com.dogzilla.maven</groupId>
<artifactId>quickstart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>quickstart</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Here's the source code:
package com.dogzilla.maven.quickstart;
import com.google.gson.Gson;
public class App
{
public static void main( String[] args )
{
Gson gson = new Gson();
System.out.println(gson.toJson("Hello World!") );
}
}
I then right-clicked on the POM file -> Run As -> Maven Build...
and here is the output:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/eclipse/java/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/opt/eclipse/java/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/eclipse/java/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/opt/eclipse/java/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.dogzilla.maven:quickstart >--------------------
[INFO] Building quickstart 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # quickstart ---
[INFO] Deleting /opt/workspace/eclipse/java/quickstart/target
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # quickstart ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/workspace/eclipse/java/quickstart/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # quickstart ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/workspace/eclipse/java/quickstart/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) # quickstart ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/workspace/eclipse/java/quickstart/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # quickstart ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/workspace/eclipse/java/quickstart/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) # quickstart ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.dogzilla.maven.quickstart.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 s - in com.dogzilla.maven.quickstart.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) # quickstart ---
[INFO] Building jar: /opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.967 s
[INFO] Finished at: 2020-12-13T20:00:27-07:00
[INFO] ------------------------------------------------------------------------
But if I run:
java -cp /opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar com.dogzilla.maven.quickstart.App
It fails with:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
at com.dogzilla.maven.quickstart.App.main(App.java:13)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
The thing is if I change System.out.println(gson.toJson("Hello World!") ); to plain 'ol System.out.println("Hello World"); it works. So I know the porblem isn't with my java command or how I set the project up outside of the dependency getting resolved.
So the question is, I'm not sure how this is failing on the dependency. I was under the impression Maven managed all that for you. Why is this failing to run?
The jar file that created from your project only contains classes that written by you. If you need to run the application, you need to include all the necessary dependencies (either direct or transitive) in your classpath.
If you need a single jar file that you can execute without other dependencies, Please follow this to create a fatjar.
Use the Maven plugin mentioned in comment https://stackoverflow.com/a/65486325/679858 or use the Maven Shade plugin described here: https://maven.apache.org/plugins/maven-shade-plugin/
Your question was "Why does it run from Eclipse and not from console?":
If you run it from Eclipse then the Maven plugin in Eclipse knows the full runtime classpath and so it works. If you run it in console with the created JAR file then that JAR file only contains the classes of your sources but not the transitive dependencies, e.g. Google GSON. But if you use the Maven Assembly plugin or the Maven Shade plugin then you can create a JAR file which contains all the transitive dependencies of your project. That jar could be executed like you wrote it in your example.
try remove gson from .m2 folder then run maven install again.
You are not providing the path to the additional, transitive, dependencies of your project in the java command, which is why it fails.
You are using maven to build your project, not to execute your class: this is not Maven purpose, although it can do it using maven-exec-plugin. Eclipse is different: it uses Maven information (with m2e) and provides a context to run classes, context that includes dependencies.
The option -cp, explained in depth at Oracle Web Site: java (15), accepts one or more path to list of directories, jar and zip to search for class files:
--class-path classpath, -classpath classpath, or -cp classpath
A semicolon (;) separated list of directories, JAR archives, and ZIP archives to search for class files.
Specifying classpath overrides any setting of the CLASSPATH environment variable. If the class path option isn't used and
classpath isn't set, then the user class path consists of the current
directory (.).
As a special convenience, a class path element that contains a base name of an asterisk (*) is considered equivalent to specifying a
list of all the files in the directory with the extension .jar or .JAR
. A Java program can't tell the difference between the two
invocations. For example, if the directory mydir contains a.jar and
b.JAR, then the class path element mydir/* is expanded to A.jar:b.JAR,
except that the order of JAR files is unspecified. All .jar files in
the specified directory, even hidden ones, are included in the list. A
class path entry consisting of an asterisk (*) expands to a list of
all the jar files in the current directory. The CLASSPATH environment
variable, where defined, is similarly expanded. Any class path
wildcard expansion that occurs before the Java VM is started. Java
programs never see wildcards that aren't expanded except by querying
the environment, such as by calling System.getenv("CLASSPATH").
So you need to fix your command to provides gson and any other compile/runtime/provided dependencies you may add later:
CLASSPATH=''
CLASSPATH+=";$HOME/.m2/repository/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar"
CLASSPATH+=";/opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar"
CLASSPATH="${CLASSPATH:1}" # remove leading ';'
java -cp "${CLASSPATH}" com.dogzilla.maven.quickstart.App
The man says that you can use ; to separate entries; that is true at least for Windows. However on other Linux based OS (which seems to are on due to /opt being used), this can also be :: that what appassembler does when writing CLASSPATH.
Do note that you will have to adapt the path manually to retarget the actual location of gson.jar (I guessed from what maven does by default).
You can also use appassembler or launch4j to do the trick for you. You can also use build-classpath to build the classpath (it may also work from command line).
TIL like I'm 5. I am not a developer. I've downloaded two udemy courses on maven and gone through both as well as gone through http://maven.apache.org/guides and nothing I've gone through really explains how to set up a project with a local (not remote) repo and what to configure and I'm getting embarrassed at how long I've spent today on trying to figure this out.
My senior person has set up a project that has the main framework things I need to plug in my scripts to run automation. I'm creating feature files/step def files on a certain project and it all uses her UI framework project with the webdriver/properties information I need. She's compiled this project in a jar file: CoreAutomationLibrary-0.0.1-SNAPSHOT.jar
Then I try to run a maven install on my project to get an initial build success so I can go through with creating my more tailored scripts.
Here is my current POM:
<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>MyAutomation</groupId>
<artifactId>MyAutomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyAutomation</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>CoreAutomationLibrary</groupId>
<artifactId>CoreAutomationLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
I'm not sure where to put this jar file.
For instance, I have her project downloaded to:
Users/myName/eclipse-workspace/HerProject
And I have my project downloaded to:
Users/myName/eclipse-workspace/RestAssured/MyProject
This jar file is floating around now, I keep moving it. I had it in my project folder just independent of anything. I tried putting it target. I'm not sure where it goes. I thought the important thing was just that it was in the build path for the project, which it is.
When I run maven install:
WARNING] The POM for CoreAutomationLibrary:CoreAutomationLibrary:jar:0.0.1-
SNAPSHOT is missing, no dependency information available
[INFO] ---------------------------------------------------------------------
---
[INFO] BUILD FAILURE
[INFO] ---------------------------------------------------------------------
---
[INFO] Total time: 0.221 s
[INFO] Finished at: 2018-06-22T11:32:44-05:00
[INFO] Final Memory: 7M/243M
[INFO] ---------------------------------------------------------------------
---
[ERROR] Failed to execute goal on project COM_UI: Could not resolve
dependencies for project COM_UI:COM_UI:jar:0.0.1-SNAPSHOT: Could not find
artifact CoreAutomationLibrary:CoreAutomationLibrary:jar:0.0.1-SNAPSHOT ->
[Help 1]
Maven usually deals with downloading dependencies itself. Propably the easiest solution in the long run is to host a repository manager like Nexus or Artifactory. Then you can configure your local maven to use this as a repository.
If this is not possible for you, you have to install the jar to your local repository using
mvn install:install-file -Dfile=Users/myName/eclipse-workspace/HerProject/her.jar -DgroupId=CoreAutomationLibrary -DartifactId=CoreAutomationLibrary -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
I have Maven project and Tomcat server.
I work in IDEA when I click in "Maven LifeCicle" -> "deploy", i have a problem:
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) # TestMaven ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.035 s
[INFO] Finished at: 2014-09-20T13:52:32+04:00
[INFO] Final Memory: 11M/93M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project TestMaven: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [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
Piace of my POM.xml is:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>tomcat</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
</plugin>
Not worked or:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
also not worked.
In the default maven lifecycle mvn deploy means to deploy one or more build artifacts to a maven repository. The reason is because the maven-deploy-plugin's deploy goal is bound to the deploy phase of the lifecycle. This configuration is automatically done when you use for example packaging jar.
In maven
a maven build lifecycle is made up of phases
a phase is made up of plugin goals
the packaging type (e.g. jar, ear, war) pre-configures plugins goals for execution in a lifecycle phase
In order to solve your problem I would first package the webapp and then invoke the deploy goal of the tomcat7-maven-plugin.
mvn package org.apache.tomcat.maven:tomcat7-maven-plugin:2.0:deploy
or simply
mvn package tomcat7:deploy
The mvn command above means:
invoke the default build lifecycle until phase package
then the goal deploy of the tomcat7 plugin.
If you want to know how maven resolves tomcat7:deploy to org.apache.tomcat.maven:tomcat7-maven-plugin:2.0:deploy you should read more about plugin groups and plugin naming conventions.
With maven deploy command, usually gets errors for various reasons.
if you work in Unix/Linux system, I recommend using "rsync" method on console. (You can write own shell script to manage easily). It helps not only deploying without a problem but also helps to get time while redeploying (only uploading changed / new files). Because maven deploy / redeploy uploads your project as a bundle in jar/war. However "rysnc" method uploads your project files one by one.
Before using it, you should sure that two conditions.
1- your project is built in target folder (Spring Tool Suite)
2- you have access to tomcat via ssh
example code : (v_ : prefix which is variable(customizable))
rsync -avz v_your_project_in_target root#v_ip:v_tomcat_name/webapps/v_project_name
I have a large JEE Maven Multi module project, and share a custom set of rules and suppressions for Checkstyle via build-tools module. I find very hard to release a stable version of this build-tools due to the testing of this same module.
Each time I run a Maven phase, I get a different execution result.
This is Checkstyle configuration in parent pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<configuration>
<skip>${skipQATests}</skip>
<configLocation>qa/checkstyle_rules.xml</configLocation>
<propertiesLocation>${checkstyleDir}/checkstyle.properties</propertiesLocation>
<suppressionsLocation>qa/suppressions.xml</suppressionsLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>checkstyle-compile</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm trying to find a pattern in the executions, project is set to fail in one particular check and I cannot find the 'bug'.
I execute compile maven phase (mvn clean compile) and it fails on the given check.
I execute package maven phase (mvn clean package) and it fails too.
I execute again compile phase (mvn clean compile) and it doesn't fail (all SUCCESS)
I execute again package and it fails
It does not fail for a couple of runs and then it fails again on some different execution
I know this behavior is kind of difficult to trace without all project information. But is there any kind of procedure, log, tool that would give more information on debuging this problem so that I can determine if it's a bug or some mis-configuration??
Thanks in advance!!
UPDATE:
I have just executed the same mvn command twice on the sub-module I'm testing Checkstyle (test that forces a rule violation) - mvn checkstyle:check -X
Result was different from each other, the main differences are that the CORRECT EXECUTION (the one that fails the build does not find the files at the first try) and the WRONG EXECUTION (the one that ends in SUCCESS finds the configuration files at the first attempt)
EXEC_1: ...
[DEBUG] The resource 'qa/suppressions.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'qa/suppressions.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/suppressions.xml.
[DEBUG] Adding the outputDirectory file:/C:/LAB/PRJ/prj-ejbws/target/classes/ to the Checkstyle class path
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/checkstyle_JEE.xml.
[DEBUG] The resource 'ubic.properties' was found as C:\LAB\PRJ\ubic.properties.
[INFO] Starting audit...
[INFO] --------------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------------
[INFO] Total time: 1.542s
[INFO] Finished at: Thu Feb 20 16:35:22 CET 2014
[INFO] Final Memory: 8M/20M
[INFO] --------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.11:check (default-cli) on project GestionDelContacto-opsa-ejbws: Failed during checkstyle execution: There are 2 checkstyle errors.
EXEC_2:...
[DEBUG] The resource 'qa/suppressions.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/suppressions.xml.
[DEBUG] Adding the outputDirectory file:/C:/LAB/PRJ/prj-ejbws/target/classes/ to the Checkstyle class path
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/checkstyle_JEE.xml.
[DEBUG] The resource 'ubic.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader.
[DEBUG] The resource 'ubic.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'ubic.properties' was found as C:\LAB\PRJ\ubic.properties.
[INFO] Starting audit...
[INFO] --------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------
[INFO] Total time: 1.570s
[INFO] Finished at: Thu Feb 20 16:37:05 CET 2014
[INFO] Final Memory: 8M/20M
[INFO] ---------------------------------------------
any clue?
Stop using Maven, run CheckStyle separately. You already have sufficient "clues": sometimes Maven initializes CheckStyle correctly, sometimes not, and depending on unreliable infrastructure is a bad idea.