JBehave
  1. JBehave
  2. JBEHAVE-829

Unable to locate stories running from CLI an executable jar built from Eclipse

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 3.6
    • Fix Version/s: 3.7
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      2

      Description

      We are trying to execute the JBehave test project from command line
      after exporting it as executable jar from Eclipse. We are facing same
      issues as JBEHAVE-729.

      Just to mention, it works fine when we run the same from Eclipse directly, having issues while running from command line as executable jar.

        Activity

        Hide
        Alexander Lehmann added a comment -

        I believe this is not the same issue as JBEHAVE-729, apparently the story files are not found inside the jar

        Show
        Alexander Lehmann added a comment - I believe this is not the same issue as JBEHAVE-729 , apparently the story files are not found inside the jar
        Mauro Talevi made changes -
        Field Original Value New Value
        Summary Issues while running JBehave project as executable jar from CLI Unable to find locate stories running from CLI an executable jar built from Eclipse
        Affects Version/s 3.6 [ 17721 ]
        Description Please find the issues details.

        Thanks Alexander for quick reply,

        Yeah we are facing issues with executable jar, where we have a class with main method and invoking a Jbehave test case. We don't have junit here.
        Just to mention, it works fine when we run the same from Eclipse directly, having issues while running from command line as executable jar.

        Will greatly appreciate any insight on this.

        Thanks,
        Suryakant


        -----Original Message-----
        From: Alexander Lehmann [mailto:alexlehm@gmail.com]
        Sent: Friday, August 31, 2012 10:58 AM
        To: Panda, Suryakant
        Cc: mauro@codehaus.org; Ganapathy, Ravi Sankar
        Subject: Re: Issues while running JBehave project as executable jar from CLI

        I'm running the example described in the issue still successfully with
        v3.6.9 on a production instance, so I'm pretty sure it works. However I'm running it via a shell script that invokes the runner from junit, maybe there is a difference with an executable jar, I never tested that.

        I can do a test project to see if it works.

        On 31.08.2012 19:53, Panda, Suryakant wrote:
        >
        > Hi Alexander, Mauro,
        >
        > We are trying to execute the JBehave test project from command line
        > after exporting it as executable jar from eclipse. We are facing same
        > issues as bug - http://jira.codehaus.org/browse/JBEHAVE-729
        >
        > We also updated Jbehave version to 3.6 which is supposed to have the
        > fix, however it doesn’t work. Are there any other pointers you can
        > provide us ?
        >
        > Thanks for help.
        >
        > Suryakant
        >

        We are trying to execute the JBehave test project from command line
        after exporting it as executable jar from Eclipse. We are facing same
        issues as JBEHAVE-729.

        Just to mention, it works fine when we run the same from Eclipse directly, having issues while running from command line as executable jar.
        Mauro Talevi made changes -
        Summary Unable to find locate stories running from CLI an executable jar built from Eclipse Unable to locate stories running from CLI an executable jar built from Eclipse
        Description
        We are trying to execute the JBehave test project from command line
        after exporting it as executable jar from Eclipse. We are facing same
        issues as JBEHAVE-729.

        Just to mention, it works fine when we run the same from Eclipse directly, having issues while running from command line as executable jar.
        We are trying to execute the JBehave test project from command line
        after exporting it as executable jar from Eclipse. We are facing same
        issues as JBEHAVE-729.

        Just to mention, it works fine when we run the same from Eclipse directly, having issues while running from command line as executable jar.
        Hide
        Mauro Talevi added a comment -

        How are you running from CLI? What don't you try using Maven or Ant to build your jars if you want to run from CLI?

        The jar you provide is not very useful. It would be more useful if you provide a same Eclipse project and told us how you run your stories from CLI.

        Show
        Mauro Talevi added a comment - How are you running from CLI? What don't you try using Maven or Ant to build your jars if you want to run from CLI? The jar you provide is not very useful. It would be more useful if you provide a same Eclipse project and told us how you run your stories from CLI.
        Hide
        Alexander Lehmann added a comment -

        The runnable jar can be run with java -jar JbehaveProject.jar, essentially this turns the whole java project into a package than can be run without requiring any additional files except java itself.

        I have taken a look at the example jar and I think I can now reproduce the issue, however I think it is not an issue with jbehave directly, it seems to be a problem finding the stories inside the jar.

        Show
        Alexander Lehmann added a comment - The runnable jar can be run with java -jar JbehaveProject.jar, essentially this turns the whole java project into a package than can be run without requiring any additional files except java itself. I have taken a look at the example jar and I think I can now reproduce the issue, however I think it is not an issue with jbehave directly, it seems to be a problem finding the stories inside the jar.
        Hide
        Alexander Lehmann added a comment - - edited

        The problem comes from the fact that running the tests inside Eclipse or Maven works quite different from running it from inside a jar.

        When running the story from the source files and classes inside Eclipse, you can use LoadFromRelativeFile and the storyPaths method can use findPaths to look up the actual files in the directory.

        Eclipse will copy the story files to bin or target directory that will also be the directory for the class that jbehave is running from (the JUnitStories subclass), when running in maven, all files are in target as well.

        When running inside the jar, the classes are found inside the jar which translates back to the local directory where is is located in, but the the findPaths methods looks in that directory and will not find anything.

        For this to work in a jar, you have to change the StoryLoader to LoadFromClasspath(getClass()), however finding the stories will not work at all.

        You can explicitly list your story files in the storyPaths method like this, this makes the stories run from the jar.

        protected List<String> storyPaths()
        {
          return Arrays.asList("stories/cx/lehmann/jbehave/jbehave_simple/stories/cleanup.story");
        }
        

        this is a bit inflexible however (if you change the list of your stories frequently) or read the list from a config file.

        If you are running the stories from the classpath in Eclipse, you have to make sure that the classpath matches the paths for the stories, if the path doesn't match, the stories will not be found inside Eclipse or inside the jar.

        Show
        Alexander Lehmann added a comment - - edited The problem comes from the fact that running the tests inside Eclipse or Maven works quite different from running it from inside a jar. When running the story from the source files and classes inside Eclipse, you can use LoadFromRelativeFile and the storyPaths method can use findPaths to look up the actual files in the directory. Eclipse will copy the story files to bin or target directory that will also be the directory for the class that jbehave is running from (the JUnitStories subclass), when running in maven, all files are in target as well. When running inside the jar, the classes are found inside the jar which translates back to the local directory where is is located in, but the the findPaths methods looks in that directory and will not find anything. For this to work in a jar, you have to change the StoryLoader to LoadFromClasspath(getClass()), however finding the stories will not work at all. You can explicitly list your story files in the storyPaths method like this, this makes the stories run from the jar. protected List< String > storyPaths() { return Arrays.asList( "stories/cx/lehmann/jbehave/jbehave_simple/stories/cleanup.story" ); } this is a bit inflexible however (if you change the list of your stories frequently) or read the list from a config file. If you are running the stories from the classpath in Eclipse, you have to make sure that the classpath matches the paths for the stories, if the path doesn't match, the stories will not be found inside Eclipse or inside the jar.
        Hide
        Alexander Lehmann added a comment -

        I have created a minimal project that can be used to show the issue, this is essentially an empty project created with the jbehave-simple archetype, the pom file creates an executable jar with the package goal.

        The resulting file can be run with java -jar jbehave-simple*.jar, which doesn't find any stories, when running the test with the unpacked files (either by running the main class in eclipse or unpacking the executable and running it with java -cp . mainclass) will find the story file.

        Show
        Alexander Lehmann added a comment - I have created a minimal project that can be used to show the issue, this is essentially an empty project created with the jbehave-simple archetype, the pom file creates an executable jar with the package goal. The resulting file can be run with java -jar jbehave-simple*.jar, which doesn't find any stories, when running the test with the unpacked files (either by running the main class in eclipse or unpacking the executable and running it with java -cp . mainclass) will find the story file.
        Hide
        Alexander Lehmann added a comment - - edited

        attached example project

        Show
        Alexander Lehmann added a comment - - edited attached example project
        Alexander Lehmann made changes -
        Attachment jbehave-simple.zip [ 61152 ]
        Hide
        Mauro Talevi added a comment -

        Let's add it to examples, e.g. under examples/executable-jar and get it working.

        Show
        Mauro Talevi added a comment - Let's add it to examples, e.g. under examples/executable-jar and get it working.
        Show
        Alexander Lehmann added a comment - moved the example to jbehave-core/examples and cleaned up the project a bit https://github.com/alexlehm/jbehave-core/commit/4f2cbaa505d64efea28ce4a55e74bb8b82141ea0 https://github.com/alexlehm/jbehave-core/commit/9eb688611c43ed97e7155839ef197baad999ae08
        Hide
        Alexander Lehmann added a comment -

        can you please mark the issue as resolved with not a bug or change it to improvement and mark it as fixed?

        Show
        Alexander Lehmann added a comment - can you please mark the issue as resolved with not a bug or change it to improvement and mark it as fixed?
        Hide
        Mauro Talevi added a comment -

        Added example showing how the story paths can be listed explicitly.

        Future enhancements should include other mechanisms to find/lookup stories in the classpath.

        Show
        Mauro Talevi added a comment - Added example showing how the story paths can be listed explicitly. Future enhancements should include other mechanisms to find/lookup stories in the classpath.
        Mauro Talevi made changes -
        Fix Version/s 3.6.10 [ 18735 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Not A Bug [ 6 ]
        Mauro Talevi made changes -
        Fix Version/s 3.7 [ 18390 ]
        Fix Version/s 3.6.10 [ 18735 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Suryakant Panda
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: