Create an executable jar using maven and a jetty

I want to run the application using the pier, so I added the following dependency. and when I run the main method, Jetty starts successfully (I am working on the struts2 + spring3 + hibernate maven project, I can also deploy it to tomcat)

Now I want to create an executable jar from the pom combat package. So I added maven-assembly-plugin to my pom. (I tried with the maven jar connection, but it did not add dependencies)

Sources

plugins

<build>
    <plugins>
        <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
                 <archive>
            <manifest>
        <mainClass>com.dca.engine.StartDCA</mainClass>
            </manifest>
             </archive>
        <packagingExcludes>WEB-INF/lib/jetty*.jar,WEB-INF/lib/org.apache.taglibs.standard.glassfish*.jar,WEB-INF/lib/org.apache.jasper.glassfish*.jar,WEB-INF/lib/org.eclipse.jdt.core*.jar,WEB-INF/lib/javax.servlet.jsp*.jar,WEB-INF/lib/javax.el*.jar</packagingExcludes>
        <escapeString>\</escapeString>
        </configuration>
       </plugin>
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
                 <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                 </descriptorRefs>
             <archive>
            <manifest>
        <mainClass>com.dca.engine.StartDCA</mainClass>
            </manifest>
             </archive>
        </configuration>
        <executions>
             <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                      <goal>single</goal>
                    </goals>
             </execution>
        </executions>
    </plugin>
 </plugins>
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
        <include>**/*.java</include>
        <include>**/*.xml</include>
        </includes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>
</build>

Built-in berth

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>8.1.10.v20130312</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-webapp</artifactId>
    <version>8.1.10.v20130312</version>
    <!-- <scope>provided</scope> -->
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-jsp</artifactId>
    <version>8.1.10.v20130312</version>
    <!-- <scope>provided</scope>  -->
</dependency> 

Main method

 Server server = new Server(8080);
        System.setProperty("is_DCA", "YES");
        WebAppContext webAppContext = new WebAppContext();
        webAppContext.setResourceBase("/home/myfolder/workspace/app/dca/src/main/webapp");
        webAppContext.setDescriptor("/home/myfolder/workspace/app/dca/src/main/webapp/WEB-INF/web.xml");
        webAppContext.setContextPath("/app");
        server.setHandler(webAppContext);
        server.start();
        server.join();

Application launch

I run the created jar with java -jar / home / myfolder / workspace / app / dca / target / app-dca-1.0-jar-with-dependencies.jar

The berth begins with an exception.

INFO  10-12 15:03:01,609 - jetty-8.y.z-SNAPSHOT
INFO  10-12 15:03:01,776 - Initializing Spring root WebApplicationContext
INFO  10-12 15:03:01,776 - Root WebApplicationContext: initialization started
INFO  10-12 15:03:01,843 - Refreshing Root WebApplicationContext: startup date [Tue Dec 10 15:03:01 IST 2013]; root of context hierarchy
INFO  10-12 15:03:01,885 - Loading XML bean definitions from class path resource [applicationContext-dca.xml]
ERROR 10-12 15:03:05,725 - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/util]
Offending resource: class path resource [applicationContext-dca.xml]

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1420)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1413)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)

, , . /WEB -INF/lib/, xml /WEB -INF/lib/,

java -jar/home/myfolder/workspace/app/dca/target/app-dca-1.0.war

.

answer

. 7.6.7.v20120910,

, 8.1.10.v20130312

+4
4

http://uguptablog.blogspot.com/2012/09/embedded-jetty-executable-war-with.html

    ProtectionDomain domain = Main.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(location.toExternalForm());
    server.setHandler(webapp);

, .

+3

, WAR , , JAR , maven-shade-plugin. :

  • "" META-INF/services, LICENSE README.
  • JAR . WAR ( ).
  • JAR , .
+8

Jetty, Tomcat, :

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <executions>
        <execution>
            <id>tomcat-run</id>
            <goals>
                <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <path>/standalone</path>
                <enableNaming>false</enableNaming>
                <finalName>standalone.jar</finalName>
                <charset>utf-8</charset>
            </configuration>
        </execution>
    </executions>
</plugin>

uberjar "standalone.jar", ,

java -jar standalone.jar

http://localhost:8080/standalone

java -jar standalone.jar -httpPort=7070

Tomasz Nurkiewicz http://www.nurkiewicz.com/2012/11/standalone-web-application-with.html

+4

, ( ), - , Jenkins CI do ( : D). Jetty ( : D), Winstone.

Maven

<plugin>
    <groupId>net.sf.alchim</groupId>
    <artifactId>winstone-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>embed</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

, ?:) - standalone - jar: app-dca-1.0-standalone.jar

+2

All Articles