Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 905607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:14:55+00:00 2026-05-15T16:14:55+00:00

I’m trying to make an executable war file ( java -jar myWarFile.war ) that

  • 0

I’m trying to make an “executable” war file (java -jar myWarFile.war) that will start up a Jetty webserver that hosts the webapp contained in the WAR file I executed.

I found a page that described how to make what I’m looking for:

However, following that advice along with how I think I’m supposed to make an executable jar (war) isn’t working.

I have an Ant task creating a WAR file with a manifest that looks like:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 1.5.0_18-b02 (Sun Microsystems Inc.)
Main-Class: Start

The contents of the WAR file look like:

> Start.class
> jsp
>   build.jsp 
> META-INF  
>   MANIFEST.MF
> WEB-INF
>   lib
>     jetty-6.1.22.jar
>     jetty-util.6.1.22.jar

When I try to execute the WAR file, the error is:

Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/Handler
Caused by: java.lang.ClassNotFoundException: org.mortbay.jetty.Handler
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Start. Program will exit.

There appears to be two errors here: one where it seems the JAR files can’t be found, and one where the Start class can’t be found.

To fix the first one, I put the Jetty JAR files in the base of the WAR file and tried again — same error. I also tried adding the WEB-INF/lib/<specific-JAR-files> to the Class-Path attribute of the manifest. That did not work either.

Does anyone have any insight as to what I’m doing right/wrong and how I can get this executable WAR file up and running?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:14:56+00:00Added an answer on May 15, 2026 at 4:14 pm

    The link you have in your question provides most of what you need. However, there are a few things that need to be done in addition to that.

    Any class files that Jetty needs to start up will need to be located at the root of the war file when it’s packaged. We can leverage Ant to do that for us before we <war> the file. The war’s manifest file will also need a Main-Class attribute to execute the server.

    Here’s a step-by-step:

    Create your Jetty server class:

    This is adapted from the link you provided.

    package com.mycompany.myapp;
    
    import java.io.File;
    import java.net.URL;
    import java.security.ProtectionDomain;
    
    import org.mortbay.jetty.Server;
    import org.mortbay.jetty.webapp.WebAppContext;
    
    public final class EmbeddedJettyServer
    {
        public static void main(String[] args) throws Exception
        {
            int port = Integer.parseInt(System.getProperty("port", "8080"));
            Server server = new Server(port);
    
            ProtectionDomain domain = EmbeddedJettyServer.class.getProtectionDomain();
            URL location = domain.getCodeSource().getLocation();
    
            WebAppContext webapp = new WebAppContext();
            webapp.setContextPath("/");
            webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
            webapp.setServer(server);
            webapp.setWar(location.toExternalForm());
    
            // (Optional) Set the directory the war will extract to.
            // If not set, java.io.tmpdir will be used, which can cause problems
            // if the temp directory gets cleaned periodically.
            // Your build scripts should remove this directory between deployments
            webapp.setTempDirectory(new File("/path/to/webapp-directory"));
    
            server.setHandler(webapp);
            server.start();
            server.join();
        }
    }
    

    To see what all you can configure here, have a look at the Jetty API documentation.

    Build the war with Ant:

    This uses a staging directory to unpack the necessary class files into the root of the war so they’re accessible when the war is executed.

    <target name="war" description="--> Creates self-executing war">
      <property name="staging.dir" location="${basedir}/staging"/>
      <property name="webapp.dir" location="${basedir}/src/webapp"/>
    
      <mkdir dir="${staging.dir}"/>
    
      <!-- assumes you have all of your war content (excluding classes and libraries) already structured in a directory called src/webapp -->
      <!-- e.g. -->
      <!-- src/webapp/index.html -->
      <!-- src/webapp/WEB-INF/web.xml -->
      <!-- src/webapp/WEB-INF/classes/my.properties -->
      <!-- etc ... -->
      <copy todir="${staging.dir}">
        <fileset dir="${webapp.dir}" includes="**/*"/>
      </copy>
    
      <unjar dest="${staging.dir}">
        <!-- you'll have to locate these jars or appropriate versions; note that these include JSP support -->
        <!-- you might find some of them in the downloaded Jetty .tgz -->
        <fileset dir="path/to/jetty/jars">
          <include name="ant-1.6.5.jar"/>
          <include name="core-3.1.1.jar"/>
          <include name="jetty-6.1.24.jar"/>
          <include name="jsp-2.1-glassfish-2.1.v20091210.jar"/><!-- your JSP implementation may vary -->
          <include name="jsp-api-2.1-glassfish-2.1.v20091210.jar"/><!-- your JSP implementation may vary -->
          <include name="servlet-api-2.5-20081211.jar"/><!-- your Servlet API implementation may vary -->
        </fileset>
        <patternset><!-- to exclude some of the stuff we don't really need -->
          <exclude name="META-INF/**/*"/>
          <exclude name="images/**/*"/>
          <exclude name=".options"/>
          <exclude name="about.html"/>
          <exclude name="jdtCompilerAdapter.jar"/>
          <exclude name="plugin*"/>
        </patternset>
      </unjar>
    
      <!-- copy in the class file built from the above EmbeddedJettyServer.java -->
      <copy todir="${staging.dir}">
        <fileset dir="path/to/classes/dir" includes="com/mycompany/myapp/EmbeddedJettyServer.class"/>
      </copy>
    
      <war destfile="myapp.war" webxml="${webapp.dir}/WEB-INF/web.xml">
        <fileset dir="${staging.dir}" includes="**/*"/>
        <classes dir="path/to/classes/dir"/><!-- your application classes -->
        <lib dir="path/to/lib/dir"/><!-- application dependency jars -->
        <manifest>
          <!-- add the Main-Class attribute that will execute our server class -->
          <attribute name="Main-Class" value="com.mycompany.myapp.EmbeddedJettyServer"/>
        </manifest>
      </war>
    
      <delete dir="${staging.dir}"/>
    </target>
    

    Execute the war:

    If everything’s set up properly above, you should be able to:

    java -jar myapp.war
    
    // or if you want to configure the port (since we are using the System property in the code)
    
    java -Dport=8443 -jar myapp.war
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As I will show, it is possible to implement the… May 16, 2026 at 5:44 pm
  • Editorial Team
    Editorial Team added an answer You can also do without use of AJAX. you can… May 16, 2026 at 5:44 pm
  • Editorial Team
    Editorial Team added an answer If you want the dot or other characters with a… May 16, 2026 at 5:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.