6

If I run my project in Eclipse all is OK. But when I do:

mvn clean 
mvn package

and afterwards start my project then it is not working. I found this difference:

Eclipse:

INFO  org.eclipse.jetty.server.Server:doStart:327 ~ jetty-9.2.13.v20150730

mvn package:

INFO  org.eclipse.jetty.server.Server:doStart:327 ~ jetty-9.2.z-SNAPSHOT

Why? What could I do, that mvn package loads the same jetty version 9.2.13?

UPDATE:

I found some additional differences:

Compiling in Eclipse (WebApplicationInitializer):

org.eclipse.jetty.server.Server:doStart:327 ~ jetty-9.2.13.v20150730
org.eclipse.jetty.server.handler.ContextHandler$Context:log:2052 ~ No Spring WebApplicationInitializer types detected on classpath

Compiling with mvn package (ServletContainerInitializers):

org.eclipse.jetty.server.Server:doStart:327 ~ jetty-9.2.z-SNAPSHOT
org.eclipse.jetty.annotations.AnnotationConfiguration:configure:456 ~ ServletContainerInitializers: detected. Class hierarchy: empty

Why does mvn not use the WebApplication?

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>de.myPro.test</groupId>
    <artifactId>AllInOneBoiler</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AllInOneBoiler</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <log4j.version>2.7</log4j.version>
        <spring.version>4.3.3.RELEASE</spring.version>
        <camel.version>2.18.3</camel.version>
        <activemq.version>5.14.5</activemq.version>
        <jolokia.version>1.3.5</jolokia.version>
        <jetty.version>9.2.13.v20150730</jetty.version>
    </properties>

    <dependencies>
        <!-- Log4J Start -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <!-- Log4J Ende -->

        <!-- Camel Start -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http4</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-mail</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-gson</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-saxon</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jdbc</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-sql</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- Camel Ende -->

        <!-- Active MQ Start -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-client</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-openwire-legacy</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-jaas</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-broker</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-console</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-shiro</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-spring</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-pool</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-jms-pool</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-amqp</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-http</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-mqtt</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-stomp</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-kahadb-store</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-leveldb-store</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-jdbc-store</artifactId>
            <version>${activemq.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq.protobuf</groupId>
            <artifactId>activemq-protobuf</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.fusesource.hawtbuf</groupId>
            <artifactId>hawtbuf</artifactId>
            <version>1.11</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jms_1.1_spec</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-annotation_1.0_spec</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xbean</groupId>
            <artifactId>xbean-spring</artifactId>
            <version>4.5</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-web</artifactId>
            <version>${activemq.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.activemq</groupId>
                    <artifactId>activemq-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Active MQ Ende -->

        <!-- Spring Start -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>



        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Spring Ende -->

        <!-- Jolokia Start -->
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
            <version>${jolokia.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-jvm</artifactId>
            <version>${jolokia.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-spring</artifactId>
            <version>${jolokia.version}</version>
        </dependency>
        <!-- Jolokia Ende -->

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <!-- Jetty Start -->
        <!-- <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-security</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-http</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-annotations</artifactId>
            <version>${jetty.version}</version>
        </dependency> -->


        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>apache-jstl</artifactId>
            <version>${jetty.version}</version>
        </dependency> 
        <dependency>
            <groupId>org.eclipse.jetty.websocket</groupId>
            <artifactId>javax-websocket-server-impl</artifactId>
            <version>${jetty.version}</version>
        </dependency> 
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>apache-jsp</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>5.1</version>
        </dependency>

        <!-- Jetty Ende -->
    </dependencies>

    <build>
        <finalName>BoilerPlate Standalone ActiveMQ and Camel</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>${camel.version}</version>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <!-- <configuration>
                    <webAppConfig>
                        <contextPath> /${project.artifactId}</contextPath >
                        <webInfIncludeJarPattern> busines-letter-*.</webInfIncludeJarPattern >
                    </webAppConfig>
                </configuration>  -->
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>5.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm-commons</artifactId>
                        <version>5.1</version>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>

                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>

                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/cxf/bus-extensions.txt</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>${mainClass}</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>org.apache.camel.spring.Main</mainClass>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                        <manifestSections>
                            <manifestSection>
                                <name>${project.name}</name>
                                <manifestEntries>
                                    <version>${project.version}</version>
                                </manifestEntries>
                            </manifestSection>
                        </manifestSections>
                    </archive>
                </configuration>
            </plugin>

            <plugin> <!-- Das Verzeichnis conf muss in diesem Projekt mit Kopiert werden, aber nicht in der JAR-Datei sein -->
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>move-main-class</id>
                        <phase>compile</phase>
                        <configuration>
                            <tasks>
                                <copy file="startEmbedded.bat" tofile="${project.build.directory}/startEmbedded.bat"/>
                                <copy todir="${project.build.directory}/conf">
                                    <fileset dir="conf/"/>
                                </copy>
                                <copy todir="${project.build.directory}/webapps">
                                    <fileset dir="webapps/"/>
                                </copy>
                                <copy todir="${project.build.directory}/lib">
                                    <fileset dir="lib/"/>
                                </copy>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Burner
  • 981
  • 19
  • 41
  • 1
    Do you mind sharing your pom.xml? How do you run your project from eclipse? If you have a launcher in Eclipse for it, sharing would help us to understand more (you can export the laucher and add to your question) – Alberto Anderick Jr May 05 '17 at 12:40
  • I inserted pom.xml. I don't think I had an launcher. I use a "run configuration" but there is only on Goals "camel:run" – Burner May 08 '17 at 08:38
  • 1
    Open the pom.xml in the eclipse editor, go to the dependencies tab and find for "jetty", maybe you have this dependency twice indirectly. – Alberto Anderick Jr May 08 '17 at 13:40
  • Yes, there are more than one, but all with the same version 9.2.13 – Burner May 09 '17 at 15:01
  • ??? All have the same Version! – Burner May 10 '17 at 08:51

4 Answers4

2

I suspect there are two versions of Maven clashing with each other.

  1. Embeded in the Eclipse IDE
  2. External configured to use.

Make sure both are same and tried to run again packaging you would get the same behavior at both places.

Also make sure that you have user settings correctly referred in Preference->Maven

Rizwan
  • 2,369
  • 22
  • 27
  • No, I use the same Maven (3.2.3) installation. Not the embedded one – Burner May 09 '17 at 15:03
  • Alternately, you can check the Dependency Hierarchy Tab in Pom file viewer, that would direct you who is resolving the jetty versions transitively to other version. As maven build precedes the latest version availability compared to older. – Rizwan May 10 '17 at 05:39
0

I suspect that your .classpath has references to hard-coded dependency versions rather than getting them dynamically from pom.xml. Here's a sure fire way of fixing maven project config in eclipse.

  1. Right click on project => Configure => Convert to Maven Project (might not need this step)
  2. Delete <projectRoot>/.classpath
  3. If you did 2. outside eclipse (eg windows explorer), right click on the project => "refresh"
  4. Right click on the project => Maven => Update Project
  5. A new .classpath should be created which has no hard-coded dependencies
lance-java
  • 25,497
  • 4
  • 59
  • 101
0

try the canonical,

mvn clean
mvn generate-sources
mvn install

I've had issues with "package" target in the past.

Yann TM
  • 1,942
  • 13
  • 22
0

Eclipse runs project differently then maven, it compiles all project classes into one folder (i.e. build or target) and executes it as java process with classpath to that build folder and jars from dependency.

And your maven config unpacks all dependencies and puts classes from them into your result.jar. That classes mixin produces unpredictable result, and thats why jetty prints wrong version, because package hierarchy is broken.

package org.eclipse.jetty.util;

public class Jetty {
  public static final String VERSION;

  private Jetty() {
  }

  static {
    Package pkg = Jetty.class.getPackage();
    if(pkg != null && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && pkg.getImplementationVersion() != null) {
      VERSION = pkg.getImplementationVersion();
    } else {
      VERSION = System.getProperty("jetty.version", "9.2.z-SNAPSHOT");
    }

  }
}
m1ld
  • 1,190
  • 9
  • 26
  • Ok, and what can I do? – Burner May 09 '17 at 15:04
  • You can create executable jar without containing all dependant classes. Instead put all dependency jars to folder named like 'lib' and specify in classpath of Manifest.MF paths to that libs. See https://maven.apache.org/shared/maven-archiver/examples/classpath.html – m1ld May 10 '17 at 05:41
  • Just realised that you already have this config. You need to remove shade plugin from your pom.xml and it won't copy classes to your jar. After that you need to put required dependencies to folder where classpath pointing. You can do it like it described here http://stackoverflow.com/a/996915/936752 – m1ld May 10 '17 at 06:08
  • I think your Answer is right, but I don't get it to run. Now I get the error message : no mainmanifestattribute in .jar – Burner May 10 '17 at 09:31
  • Ok, I get the project run with the command line "mvn camel:run", but a mvn package don't work. – Burner May 10 '17 at 12:31
  • Well. Never used Camel, but as I see camel:run is just for development purposes and package for distribution. You still need to learn how to build correct executable jar with maven in the future. – m1ld May 10 '17 at 16:40