Skip to content

withFileFromClasspath does not work for resources within a jar #213

Closed

Description

@hcoles

As per the title ClasspathTrait.withFileFromClassPath fails with

Can't get size from blah blah blah path/SKYNET-0.7-SNAPSHOT.jar!/com/example/Dockerfile

When it is given a classpath resource within a jar.

For the moment I'm working round this with a transferable that copies the resource to a byte array

  static Transferable fromClasspath(final String resourcePath) {
    URL resource = ClasspathTrait.class.getClassLoader()
        .getResource(resourcePath);

    try (InputStream stream = resource.openStream()) {
      byte[] bytes = IOUtils.toByteArray(stream);

      return new Transferable() {
        @Override
        public long getSize() {
          return bytes.length;
        }

        @Override
        public void transferTo(OutputStream outputStream) {
          try {
            IOUtils.write(bytes, outputStream);
          } catch (IOException e) {
            throw new RuntimeException(
                "Can't transfer resource " + resourcePath, e);
          }
        }
      };
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  };

But it would be preferable for the DSL to support this.

Activity

  1. modified the milestone: 1.1.7 on Nov 19, 2016
  2. rnorth commented on Nov 20, 2016

    @rnorth
    Member

    Fix released in 1.1.7 - sorry for the delay in getting this out.

    The mounting of classpath resources from JAR files entails copying them out to a temporary folder, from where docker is able to mount it. This is used for loading default MySQL and MariaDB configurations now, so hopefully functions for your use case as well. There's no API change - just use withClasspathResourceMapping on any subclass of GenericContainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions