3

i am trying to use the spring boot properties launcher

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>org.springframework.boot.loader.PropertiesLauncher</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Start-Class>com.att.hadoop.loader.run.Application</Start-Class>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>

when i look at manifest file it looks like this

$ unzip -q -c hdfsloader-0.0.1-SNAPSHOT.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Built-By: aq728y
Build-Jdk: 1.7.0_25
Start-Class: org.springframework.boot.loader.PropertiesLauncher
Created-By: Apache Maven 3.1.0
Spring-Boot-Version: 1.0.0.RC1
Main-Class: org.springframework.boot.loader.JarLauncher
Archiver-Version: Plexus Archiver

any ideas on why my mainclass and startclass are wrong

I want to set it as

Main-Class: org.springframework.boot.loader.PropertiesLauncher

Start-Class: com.att.hadoop.loader.run.Application

adeelmahmood
  • 2,371
  • 8
  • 36
  • 59

1 Answers1

13

The spring-boot-maven-plugin rewrites your manifest, and in particular it manages the Main-Class and Start-Class entries, so you have to configure those there (not in the jar plugin). The Main-Class in the manifest is actually controlled by the layout property of the boot plugin, e.g.

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>1.0.0.RC1</version>
  <configuration>
    <mainClass>${start-class}</mainClass>
    <layout>ZIP</layout>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>repackage</goal>
      </goals>
    </execution>
  </executions>
</plugin>

The layout property defaults to a guess based on the archive type (JAR or WAR). For the PropertiesLauncher the layout is "ZIP".

Dave Syer
  • 56,583
  • 10
  • 155
  • 143
  • thanks .. this work. one question i have is that i have files in src/main/resources and I am trying to access them as ClassPathResoure("classpath:datasource.props") .. and it works in eclipse but after building boot jar file it cant find this file. HOw are these class path resources available to the application – adeelmahmood Jan 24 '14 at 16:03
  • Sounds like that should work. The default settings for the jar plugin would put those files in the root of the archive. Can you check they are there? What is your classpath setting? – Dave Syer Jan 24 '14 at 16:26
  • the files from resource folder do seem to be in the root of the jar and not sure about classpath setting. I am not specifying anything explicitly. The code to retrive the file looks like this "r = new ClassPathResource(path.replaceFirst("classpath:", ""));" – adeelmahmood Jan 24 '14 at 17:36
  • the error looks like this: class path resource [datasource.properties] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/opt/data/stage01/ecdw/foundry/dev/eqfx/aq728y/wars/hdfsloader-0.0.1-SNAPSHOT.jar!/datasource.properties – adeelmahmood Jan 24 '14 at 17:43
  • How are you running the app? It works for me with "java -jar". That error message says it is looking for a file resource (not a classpath resource), so I'm not 100% convinced we've seen the whole picture yet. – Dave Syer Jan 24 '14 at 18:31
  • This is how things are setup `String path = "classpath:datasource.properties";` `Resource r = new ClassPathResource(path.replaceFirst("classpath:", ""));` and I am running the app like this `java -jar hdfsloader-0.0.1-SNAPSHOT.jar` – adeelmahmood Jan 24 '14 at 18:57