<p>So is there a way to initialize and start a command line Spring app without writing a main method. It seems like all such main methods have the same form</p>

<pre><code>public static void main(final String[] args) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", Boot.class);
    FooService fooService = (FooService) ctx.getBean("fooService");
    fooService.bar();
}
</code></pre>

<p>I suppose that's not complicated, but has someone found a way to provide a way to just specify the <code>context.xml</code> at the command line or, better yet, in a manifest file?</p>

<p>The goal here is to simplify the creation of spring applications as executable jars. I hope that I can specify some utility class as the <code>Main-Class</code> in the manifest. I suppose I would also need to specify the starting point for the app, a bean and a method on it where begins the process.</p>

I'll try to answer the question as I understand it:
How to package a jar containing a spring configuration such as I just need to use
```
java -jar myjar.jar
```
?
The code snippet you have in your question simply works. You don't have to parameterise the
```
context.xml
```
. You just need to bundle your code and its dependencies (spring, etc.) in a single jar with a proper manifest entry for the main class in a jar file.
I personaly use
maven 2
and here is a
pom.xml
I would use that do just that:
```
```
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow</groupId>
  <artifactId>stackoverflow-autostart-spring-app</artifactId>
  <version>0.1</version>

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
      <version>2.5.2</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.stackoverflow.spring.autostart.Autostart</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
```
```
This is assuming some package name for the java code, the source code being in the
```
src/main/java
```
directory and the file
```
context.xml
```
in the
```
src/main/resources
```
directory.
So in this
```
pom.xml
```
there are several important points:
the spring dependency (speaks for itself I believe)
the configuration of the
maven jar plugin
, that adds the main class as a manifest entry
the
maven shade plugin
, which is the plugin responsible for gathering all the dependencies/classes and packaging them into one single jar.
The executable jar will be available at
```
target\stackoverflow-autostart-spring-app-0.1.jar
```
when running
```
mvn package
```
.
I have this code all working on my box but just realised that I can't attach a zip file here. Anyone know of place I could do so and link here?
I created a
git repository at github
with the code related to this question if you want to check it out.
Hope this helps.