Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@stackmystack
Copy link
Contributor

@stackmystack stackmystack commented Mar 24, 2023

When running java -jar project.jar -S, the extraction process:

  1. Creates a tmp folder, deleted on process exit
  2. Extracts files and folders from the jar to the tmp folder
    1. The layout in tmp is different than that of the war
    2. It's an attempt to pull back all the files and folders back in their original layout: how they were layed out before running warble runnable war at the root of the project.

This patch addresses step 2.

Previously, only files at the root were pulled back to /public, leaving behind other directories at the root of the tmp.

This is an issue because of Rails.public_path.

When running the war inside a web container like tomcat:

`Rails.public_path` = `war` root

When running the war with java -jar:

`Rails.public_path` = `/tmp/jruby…extract/public`

So if you try to access resources from:

`Rails.public_path / 'some' / 'nested' / 'path' / 'here.file'`

You're not going to find it because it's in:

`Rails.root / 'some' / 'nested' / 'path' / 'here.file'`

This commit pulls back everything that is not META-INF back into public.

While this is —theoretically– the inverse operation of the bundling process, its soundness lives in code and not in data.

The optimal solution would be to bundle in the war a file listing all transformations that happened and reversing them properly when needed for java -jar execution.

But to be completely honest, I don't understand why it was done this way in the first place, so maybe the whole thing is doing something wrong. However, the test suite is not complaining (I ran it in my own repo).

When running `java -jar project.jar -S`, the extraction process:

1. Creates a `tmp` folder, deleted on process exit
2. Extracts files and folders from the `jar` to the `tmp` folder
  1. The layout in `tmp` is different than that of the `war`
  2. It's an attempt to pull back all the files and folders back in
     their original layout: how they were layed out before running
     `warble runnable war` at the root of the project.
3. …

This patch addresses step 2.

Previously, only files at the root were pulled back to `/public`,
leaving behind other directories at the root of `/tmp`.

This is an issue because of `Rails.public_path`.

When running the `war` inside a web container like `tomcat`:

    `Rails.public_path` = `war` root

When running the `war` with `java -jar`:

    `Rails.public_path` = `/tmp/jruby…extract/public`

So if you try to access resources from:

    `Rails.public_path / 'some' / 'nested' / 'path' / 'here.file'`

You're not going to find it because it's in:

    `Rails.root / 'some' / 'nested' / 'path' / 'here.file'`

This commit pulls back everything that is not `META-INF` back into
public.

While this is —theoretically– the inverse operation of the bundling
process, its soundness lives in code and not in data.

The optimal solution would be to bundle in the war a file listing all
transformations that happened and reversing them properly when needed
for `java -jar` execution.
@stackmystack
Copy link
Contributor Author

I added the missing lib/warbler_jar.jar.

@stackmystack
Copy link
Contributor Author

stackmystack commented May 26, 2023

Hi,

Can someone please review this PR?

@nicksieger @jkutner @kares I am tagging you guys because you're top contributors, and I don't know who's maintaining the project.

Copy link
Member

@kares kares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

and I don't know who's maintaining the project.

that would be the @jruby/team-jruby-github-com at this point

@kares kares merged commit 662d87e into jruby:master May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants