[play-mini 2.0.1] Generating jar with sbt-assembly

1,556 views
Skip to first unread message

André Silva

unread,
May 25, 2012, 6:32:15 AM5/25/12
to play-fr...@googlegroups.com
Hi,

I'm trying to generate a jar with sbt-assembly. I'm using a template play-mini project generated with g8.

If I try to run the assembly task I get the following error:

[info] merging 'META-INF/ASL2.0' with strategy 'deduplicate'
[info] merging 'META-INF/spring.schemas' with strategy 'filterDistinctLines'
[info] merging 'META-INF/spring.handlers' with strategy 'filterDistinctLines'
[error] {file:/Users/beat/Desktop/my_app/}my_app/*:assembly: deduplicate: different file contents found in the following:
[error] /Users/beat/.ivy2/cache/org.springframework/spring-context/jars/spring-context-3.0.7.RELEASE.jar:META-INF/spring.tooling
[error] /Users/beat/.ivy2/cache/org.springframework/spring-beans/jars/spring-beans-3.0.7.RELEASE.jar:META-INF/spring.tooling

I can get around it by adding the following to my Build.scala:

    ivyXML :=
      <dependencies>
          <exclude org="org.springframework"/>
      </dependencies>,

The jar is generated successfully but when I try to run it I get the following error:

λ my_app → java -jar target/my_app-assembly-2.0.1.jar 
Failed to load Main-Class manifest attribute from
target/my_app-assembly-2.0.1.jar

I tried setting the mainClass for the assembly task specifically on the build file.

mainClass in assembly := Some("play.core.server.NettyServer"),

But sbt-assembly still doesn't add it to the manifest file of the jar. 
If I edit the manifest file and add the main class the jar works as expected.

I know this issue is not related to Play itself, but I'm trying to generate one jar to bundle my application and I'd appreciate any help I can get.

I'm open to any other alternatives, I don't have to rely on sbt-assembly to generate the jar. I've tried one-jar but I didn't have any luck either. I was able to generate the jar
but then the server would crash as soon as it started because the ehcache.xml file was not found (this issue was already reported here (https://groups.google.com/group/play-framework/browse_thread/thread/9b473d86538850d9/1f06fff91e5b0a08).

Cheers!

virtualeyes

unread,
May 25, 2012, 8:20:31 AM5/25/12
to play-framework
This worked for me in a Scalatra project:

in Build.scala > settings block

// workaround assembly duplication error for common files
excludedFiles in assembly := {
(bases: Seq[File]) =>
bases flatMap {
base =>
(base / "META-INF" * "*").get collect {
case f if f.getName.toLowerCase == "manifest.mf" => f
}
}
},
mergeStrategy in assembly ~= {
old => {
case "META-INF/NOTICE.txt" => MergeStrategy.filterDistinctLines
case "META-INF/NOTICE" => MergeStrategy.filterDistinctLines
case "META-INF/LICENSE.txt" => MergeStrategy.filterDistinctLines
case "META-INF/LICENSE" => MergeStrategy.filterDistinctLines
case x => old(x)
}
}

Your mileage may vary...

There is also this:
http://www.playframework.org/documentation/2.0/ProductionDist
> (https://groups.google.com/group/play-framework/browse_thread/thread/9...).
>
> Cheers!

André Silva

unread,
May 28, 2012, 6:32:16 AM5/28/12
to play-framework
That didn't work for me.

The problem with Play's dist is that it isn't available on Play Mini
applications.
> > /Users/beat/.ivy2/cache/org.springframework/spring-beans/jars/spring-beans- 3.0.7.RELEASE.jar:META-INF/spring.tooling

peter hausel

unread,
May 28, 2012, 10:38:33 PM5/28/12
to play-fr...@googlegroups.com
could you please report this issue at https://github.com/sbt/sbt-assembly/issues ? thanks Peter

peter hausel

unread,
May 28, 2012, 10:59:45 PM5/28/12
to play-fr...@googlegroups.com
if you add 

.settings(
    mainClass in assembly := Some("play.core.server.NettyServer")
  )

*after* the assembly settings are included the manifest should be populated properly (I will add this snippet to the g8 template).

As for the spring error it would be good to understand what's causing the issue for assembly in the first place, depending on Eugene's answer we could adjust the g8 template.

Thanks,
Peter

peter hausel

unread,
May 28, 2012, 11:17:16 PM5/28/12
to play-fr...@googlegroups.com
I changed the play-mini templates. The only remaining question is what to do with the spring manifest issue (effecting only java users). Cheers, Peter

peter hausel

unread,
May 28, 2012, 11:46:07 PM5/28/12
to play-fr...@googlegroups.com
ok, worked around the spring manifest issue completely, so both scala and java templates should be working now. Thanks.

André Silva

unread,
May 30, 2012, 7:07:28 AM5/30/12
to play-framework
I've checked out your updated template and merged in the changes.
Everything is working flawlessly now! Thank you very much for your
help.

Cheers!

On May 29, 4:46 am, peter hausel <peter.hau...@gmail.com> wrote:
> ok, worked around the spring manifest issue completely, so both scala and
> java templates should be working now. Thanks.
>
>
>
>
>
>
>
> On Monday, May 28, 2012 11:17:16 PM UTC-4, peter hausel wrote:
>
> > I changed the play-mini templates. The only remaining question is what to
> > do with the spring manifest issue (effecting only java users). Cheers, Peter
>
> > On Monday, May 28, 2012 10:59:45 PM UTC-4, peter hausel wrote:
>
> >> if you add
>
> >> .settings(
> >>     mainClass in assembly := Some("play.core.server.NettyServer")
> >>   )
>
> >> *after* the assembly settings are included the manifest should be
> >> populated properly (I will add this snippet to the g8 template).
>
> >> As for the spring error it would be good to understand what's causing the
> >> issue for assembly in the first place, depending on Eugene's answer we
> >> could adjust the g8 template.
>
> >> Thanks,
> >> Peter
>
> >> On Monday, May 28, 2012 10:38:33 PM UTC-4, peter hausel wrote:
>
> >>> could you please report this issue at
> >>>https://github.com/sbt/sbt-assembly/issues? thanks Peter
Reply all
Reply to author
Forward
0 new messages