weavejester / lein-ring

Ring plugin for Leiningen
Eclipse Public License 1.0
501 stars 99 forks source link

lein-ring uberjar incompatible with profile-specific :target-path #116

Open paulbutcher opened 10 years ago

paulbutcher commented 10 years ago

lein-ring’s uberjar command seems to be incompatible with Leiningen’s profile-specific :target-path.

Generate a project with lein new compojure foo, build with lein ring uberjar and run with java -jar target/foo-0.1.0-SNAPSHOT-standalone.jar and everything works fine.

However, add this to project.clj:

:target-path "target/%s"

And the generated uberjar (which will now be in target/uberjar) is missing the main class:

$ java -jar target/uberjar/foo-0.1.0-SNAPSHOT-standalone.jar 
Error: Could not find or load main class foo.handler.main
weavejester commented 10 years ago

I suspect that this line is causing the issue. It should probably be :target-path rather than :compile-path.

paulbutcher commented 10 years ago

That doesn't seem to be it, I'm afraid. The only difference between :compile-path and :target-path is that :compile-path has "/classes" appended. Switching to :target-path breaks things.

As far as I can work out (although I'm not at all familiar with Leiningen's internals, so I may well have this wrong), the problem seems to be that main is being compiled before the uberjar profile is merged into the project. So when main is compiled, :compile path is target/base+system+user+dev/classes instead of target/uberjar/classes.

I tried merging the uberjar profile before compiling main, like https://github.com/weavejester/lein-ring/pull/104 does, but that doesn't address the problem either (it just seems to confuse matters because Leiningen doesn't like having the profile merged twice).

So I'm at a loss - the only way forward I can see right now is to copy Leiningen's uberjar task and add jar/compile-main to it after the uberjar profile has been merged into the project. Eugh!

razum2um commented 10 years ago

faced this issue too :(

cbegin commented 10 years ago

faced this issue too :(

pjstadig commented 9 years ago

There is a similar problem with the ring uberwar task.

pjstadig commented 9 years ago

I think this issue should be closed. On lein-ring 0.9.3 it seems to be fixed to me. Is there a particular case that can reproduce a failure? I did the following to verify (which is essentially the same case as the original report by @paulbutcher)

lein new compojure ring-116
# change lein-ring version to 0.9.3
java -jar target/ring-116-0.1.0-SNAPSHOT-standalone.jar
rm -rf target
# add target-path to project.clj
lein ring uberjar
java -jar target/uberjar/ring-116-0.1.0-SNAPSHOT-standalone.jar