[JVM] Creating an executable jar of Features

219 views
Skip to first unread message

C0deAttack

unread,
Apr 25, 2012, 3:53:14 PM4/25/12
to cu...@googlegroups.com
Hi,

I'm attempting to create an executable Jar with dependencies with Maven, but I've not seem to have got it quite right.

I'm wondering if any one else may have already tried this and could help? I've got as far as creating the Jar but running the main method in cucumber.cli.Main isn't finding any feature files.

The motivation for this is so the Jar can be dropped on to any machine to run the features.

Thanks.

Thomas Sundberg

unread,
Apr 26, 2012, 12:50:46 AM4/26/12
to cu...@googlegroups.com
On Wed, Apr 25, 2012 at 21:53, C0deAttack <c0deatt...@gmail.com> wrote:
> Hi,
>
> I'm attempting to create an executable Jar with dependencies with Maven, but
> I've not seem to have got it quite right.
>
> I'm wondering if any one else may have already tried this and could help?
> I've got as far as creating the Jar but running the main method in
> cucumber.cli.Main isn't finding any feature files.

Sounds like a path problem. Your features may not be available on the
class path the main has access to. Can you find you features if you
disassemble the generated jar?

You might find some usable information about executable jars here:
http://maven.apache.org/shared/maven-archiver/examples/classpath.html

HTH
Thomas

>
> The motivation for this is so the Jar can be dropped on to any machine to
> run the features.
>
> Thanks.
>
> -- There are two rules:
>
> 1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people
> to filter messages.
> 2) Please use interleaved answers
> http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
>
> You received this message because you are subscribed to the Google Groups
> Cukes group. To post to this group, send email to cu...@googlegroups.com. To
> unsubscribe from this group, send email to
> cukes+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/cukes?hl=en



--
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

C0deAttack

unread,
Apr 27, 2012, 8:06:25 AM4/27/12
to cu...@googlegroups.com


On Thursday, April 26, 2012 5:50:46 AM UTC+1, Thomas Sundberg wrote:
On Wed, Apr 25, 2012 at 21:53, C0deAttack <c0deatt...@gmail.com> wrote:
> Hi,
>
> I'm attempting to create an executable Jar with dependencies with Maven, but
> I've not seem to have got it quite right.
>
> I'm wondering if any one else may have already tried this and could help?
> I've got as far as creating the Jar but running the main method in
> cucumber.cli.Main isn't finding any feature files.

Sounds like a path problem. Your features may not be available on the
class path the main has access to. Can you find you features if you
disassemble the generated jar?

You might find some usable information about executable jars here:
http://maven.apache.org/shared/maven-archiver/examples/classpath.html

HTH
Thomas


Yep, the Jar itself looks fine when I explode and inspect it.

This is the basic structure of the contents:
- /
--- /com.executabletests.steps
--- /lib/... (Jars like cucumber-java etc)
--- /features (The Feature files)
--- META_INF/MANIFEST.MF


The classpath in the manifest:

Class-Path: features/ lib/ lib/cucumber-core-1.0.4.jar etc....

So I would have thought that executing "java -jar executable-tests-1.0.jar --glue com.executabletests.steps --format pretty features" would work but the Features in "features" directory are not found. Everything works fine when the jar is exploded. so it's just something in the way I've set the Class-Path in the Manifest.mf that must be wrong.


C0deAttack

unread,
Apr 28, 2012, 1:27:56 PM4/28/12
to cu...@googlegroups.com
I've given up on this. I went and had a look in the code and the Features are not loaded as resources through a classloader from what I can tell, so that's why I believe it has not worked.


Aslak Hellesøy

unread,
Apr 28, 2012, 5:11:14 PM4/28/12
to cu...@googlegroups.com




On Apr 28, 2012, at 12:27, C0deAttack <c0deatt...@gmail.com> wrote:

I've given up on this. I went and had a look in the code and the Features are not loaded as resources through a classloader from what I can tell, so that's why I believe it has not worked.


Actually, they are. Via ClasspathResourceLoader

Aslak

C0deAttack

unread,
Apr 29, 2012, 5:33:40 AM4/29/12
to cu...@googlegroups.com


On Saturday, April 28, 2012 10:11:14 PM UTC+1, Aslak Hellesøy wrote:


On Apr 28, 2012, at 12:27, C0deAttack wrote:

I've given up on this. I went and had a look in the code and the Features are not loaded as resources through a classloader from what I can tell, so that's why I believe it has not worked.


Actually, they are. Via ClasspathResourceLoader

Aslak


I hate to say "are you sure?" since this is your project, but are you sure? This is the line from the run() method invoked in the cucumber.cli.Main class:

Runtime runtime = new Runtime(new FileResourceLoader(), classLoader, runtimeOptions);

Unless I've got this wrong and misunderstood something that FileResourceLoader doesn't try to load anything via the Classpath?

Regards,
C0de.

aslak hellesoy

unread,
Apr 30, 2012, 4:40:50 PM4/30/12
to cu...@googlegroups.com
On Sun, Apr 29, 2012 at 4:33 AM, C0deAttack <c0deatt...@gmail.com> wrote:
>
>
> On Saturday, April 28, 2012 10:11:14 PM UTC+1, Aslak Hellesøy wrote:
>>
>>
>>
>> On Apr 28, 2012, at 12:27, C0deAttack wrote:
>>
>> I've given up on this. I went and had a look in the code and the Features
>> are not loaded as resources through a classloader from what I can tell, so
>> that's why I believe it has not worked.
>>
>>
>> Actually, they are. Via ClasspathResourceLoader
>>
>> Aslak
>>
>
> I hate to say "are you sure?" since this is your project, but are you sure?

Touché. The CLI runner uses the file system (fs) to load resources,
the JUnit runner uses the classpath (cp). When I made this decision a
while back I was thinking that the CLI runner would primarily be used
by non-java backends (clojure, jruby, jython etc) that are less likely
to rely on the cp for loading features. Likewise, people using the
JUnit runner are more likely to be using the java backend, and would
need the cp loader.

I now realise it's not that simple. The decision whether to use the fs
or cp should be made by the backend (java, groovy, jruby, clojure etc)
and not byt the runner (junit or CLI).

In some cases a backend might want both. This is the case for Groovy
which might want to load glue code from the fs (.groovy sources) or
from the cp (compiled groovy .class files).

I have created a new ticket for this where you can contribute your
thoughts on this:
https://github.com/cucumber/cucumber-jvm/issues/312

Aslak

> This is the line from the run() method invoked in the cucumber.cli.Main
> class:
>
> Runtime runtime = new Runtime(new FileResourceLoader(), classLoader,
> runtimeOptions);
>
> Unless I've got this wrong and misunderstood something that
> FileResourceLoader doesn't try to load anything via the Classpath?
>
> Regards,
> C0de.
>

C0deAttack

unread,
May 1, 2012, 3:39:58 PM5/1/12
to cu...@googlegroups.com
That's great, thanks. I've read the ticket and I think what you've said makes sense and commented as such.
Reply all
Reply to author
Forward
0 new messages