Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: lein plugin for capsule #39

Closed
yogthos opened this issue May 22, 2015 · 25 comments
Closed

feature request: lein plugin for capsule #39

yogthos opened this issue May 22, 2015 · 25 comments
Assignees
Labels

Comments

@yogthos
Copy link

yogthos commented May 22, 2015

Since Leiningen is the de facto build tool for Clojure, it would be nice if there was a plugin for packaging capsule jars.

@circlespainter
Copy link
Member

There's https://github.com/circlespainter/lein-capsule, it's 3rd-party for now and needs to be updated to the latest capsule versions but it might work for you.

@yogthos
Copy link
Author

yogthos commented May 22, 2015

that looks promising, any plans to support it officially?

@circlespainter
Copy link
Member

There aren't official support plans about it at the moment.

@yogthos
Copy link
Author

yogthos commented May 22, 2015

Seeing how there's already a working plugin it would be nice to provide it officially as pretty much anybody working with Clojure is likely to be using Leiningen. The fact that you have to use a separate build tool is a big deterrent.

@circlespainter
Copy link
Member

Keeping it working and regularly updated is definitely important. Have you tried it anyways? Does it work for you?

@yogthos
Copy link
Author

yogthos commented May 23, 2015

Doesn't appear to work no, it compiles and generates a jar, but running it produces:

Exception in thread "main" java.lang.ExceptionInInitializerError
...
Caused by: java.lang.ClassNotFoundException: co.paralleluniverse.strands.SuspendableCallable

Which I'm assuming means the agent is not being injected. Also, out of curiosity why is it not possible to build pulsar with plain Leiningen as it allows specifying java agents, is there something else that happens during capsule packaging?

@pron
Copy link
Contributor

pron commented May 23, 2015

Hi.

  1. Capsule is not at all required to package and/or run applications using Pulsar.
  2. Capsule itself -- while completely production ready -- is not an "official" product (though it may be).
  3. @circlespainter 's Leiningen plugin might work with Capsule 0.10.0, but not 1.0
  4. The Leiningen plugin will be brought up to date when @circlespainter has the time, but any help would be appreciated.
  5. Unrelated, but you'd might like to know: the upcoming Pulsar release, 0.7.0, (in a few weeks) will contain some great improvements, such as bringing core.async compatibility up to date.

Again: Pulsar and Capsule are completely orthogonal, and none of them requires the other.

@yogthos
Copy link
Author

yogthos commented May 23, 2015

Thanks for the explanation, I guess the question is then if there is a concrete example available of a pulsar application packaged with Leiningen if that's possible. The official docs show how to use lein run to launch the application, but not how to generate a runnable jar for deployment.

@pron
Copy link
Contributor

pron commented May 23, 2015

No, we don't have an example (we'll add one). The only "special" thing you need to pay attention to is adding the javaagent to the command line (pointing to the quasar-core jar). If packing into an uberjar (haven't tried this myself), you'll be able to point the javaagent flag to the uberjar itself, but then you'll need the uberjar's manifest to specify that it contains an agent:

Premain-Class: co.paralleluniverse.fibers.instrument.JavaAgent
Agent-Class: co.paralleluniverse.fibers.instrument.JavaAgent
Can-Retransform-Classes: true
Can-Redefine-Classes: true

@yogthos
Copy link
Author

yogthos commented May 23, 2015

thanks that makes sense

@yogthos
Copy link
Author

yogthos commented May 23, 2015

So, I tried creating an uberjar that contains the above properties in the manifest, however I still get java.lang.RuntimeException: Java agent not running.

I added the manifest properties in project.clj

:manifest {"Premain-Class" "co.paralleluniverse.fibers.instrument.JavaAgent"
               "Agent-Class" "co.paralleluniverse.fibers.instrument.JavaAgent"
               "Can-Retransform-Classes" "true"
               "Can-Redefine-Classes" "true"}

Extracting the jar built using lein uberjar the manifest contains the following:

cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Premain-Class: co.paralleluniverse.fibers.instrument.JavaAgent
Built-By: Yogthos
Can-Redefine-Classes: true
Agent-Class: co.paralleluniverse.fibers.instrument.JavaAgent
Can-Retransform-Classes: true
Created-By: Leiningen 2.5.1
Build-Jdk: 1.8.0_25
Main-Class: pulsar_example.core

the sample project can be found here

everything works fine when using lein run however

@pron
Copy link
Contributor

pron commented May 23, 2015

Have you added -javaagent:uber.jar to the command line?

@yogthos
Copy link
Author

yogthos commented May 23, 2015

ah thanks that works

java -javaagent:quasar-core-0.6.2.jar -jar target/pulsar-example-0.1.0-SNAPSHOT-standalone.jar

@pron
Copy link
Contributor

pron commented May 23, 2015

You don't need the quasar-core JAR anymore, now that you have the manifest entries (or, alternatively, you don't need the manifest entries if you're using the quasar-core JAR). Try:

java -javaagent:target/pulsar-example-0.1.0-SNAPSHOT-standalone.jar -jar target/pulsar-example-0.1.0-SNAPSHOT-standalone.jar

Now capsule indeed lets you embed the command line flags (for the agent or anything else) in the JAR file, and it also prevents other collisions that may (and do) happen when building a fat JAR. You might want to try the leningen plugin with Capsule 0.10.0 or 0.9.0 until it is updated.

@yogthos
Copy link
Author

yogthos commented May 23, 2015

Yeah, I updated to add [co.paralleluniverse/quasar-core "0.6.2"] to the dependencies and it works with just the uberjar now. Packaging with capsule would be ideal, but not either way I think it's pretty reasonable. 👍

@yogthos
Copy link
Author

yogthos commented Jun 16, 2015

@pron
I'm having an odd behavior with 0.7 where the actors don't appear to receive messages:

Here's the sample project

All I see is Pong received ping, but the ping function never receives the :ping message:

lein run
Compiling pulsar-example.core
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Pong received ping

the same happens when I do

lein uberjar
java -javaagent:target/pulsar-example.jar -jar target/pulsar-example.jar

This is on OS X 10.10.3 and JDK 1.8.0, is there something obvious I'm missing here?

@pron
Copy link
Contributor

pron commented Jun 17, 2015

This was caused by an AOT-related bug which has now been fixed. Thanks for reporting.

@circlespainter
Copy link
Member

@yogthos You should also join the actors before returning from the main thread, else you risk exiting before they complete.

@yogthos
Copy link
Author

yogthos commented Jun 17, 2015

Great thanks for the quick response, and I updated the example to use join. Are you releasing the fix to Clojars?

@pron
Copy link
Contributor

pron commented Jun 17, 2015

A new Quasar/Pulsar bug-fix version will be released in a few days. If you want, you can try 0.7.1-SNAPSHOT which is already up on Clojars.

@yogthos
Copy link
Author

yogthos commented Jun 17, 2015

excellent, and can confirm everything is working as excpeted

@circlespainter
Copy link
Member

@yogthos The current master of lein-capsule should work with the latest Capsule. If you try it let me know if it works for you too.

@yogthos
Copy link
Author

yogthos commented Aug 23, 2015

Great thanks, I'll let you know if I run into anything funky.

@circlespainter
Copy link
Member

There's now lein-capsule 0.2.0 available too for Capsule 1.0+.

@circlespainter
Copy link
Member

This is an example application using it: https://github.com/circlespainter/capsule-1.0-sample/tree/master/clj-lein

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants