Homebrew / legacy-homebrew

💀 The former home of Homebrew/homebrew (deprecated)
https://brew.sh
26.98k stars 11.35k forks source link

How to distribute a java app (jar file with bash launcher) through Homebrew? #41680

Closed Krasnyanskiy closed 9 years ago

Krasnyanskiy commented 9 years ago

I have two files: executable jar file jrsh-2.0.4.jar and jrsh.sh script to run the jar. I want to run it through the Homebrew. What should I do to make it possible?

My run.sh script

#!/usr/bin/env bash
java -jar *.jar $*

I created a tar.gz file and made a formula

brew create 'path/to/my/jrsh-2.0.4.tar.gz'

Then I downloaded it using brew install jrsh. But it doesn't work.

DomT4 commented 9 years ago

Something like this would work. You could either permit Homebrew to create a new Jar script for you, or simply replace bin.write_jar_script with bin.install_symlink libexec/"run.sh". Should work. Let us know if you hit any further issues.

Krasnyanskiy commented 9 years ago

I got this error

$ brew install jrsh
Error: undefined method `desc' for Formulary::Formulae::Jrsh:Class
Please report this bug:
    https://git.io/brew-troubleshooting
/usr/local/Library/Formula/jrsh.rb:2:in `<class:Jrsh>'
/usr/local/Library/Formula/jrsh.rb:1:in `load_file'
/usr/local/Library/Homebrew/formulary.rb:92:in `module_eval'
/usr/local/Library/Homebrew/formulary.rb:92:in `load_file'
/usr/local/Library/Homebrew/formulary.rb:82:in `klass'
/usr/local/Library/Homebrew/formulary.rb:71:in `get_formula'
/usr/local/Library/Homebrew/formulary.rb:200:in `factory'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `block in formulae'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `map'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `formulae'
/usr/local/Library/Homebrew/cmd/install.rb:41:in `install'
/usr/local/Library/brew.rb:140:in `<main>'

Here is my jrsh.rb file

class Jrsh < Formula
  desc "A Command Line Interface for JasperReports Server"
  homepage "https://github.com/Krasnyanskiy/jrsh/"
  url "https://github.com/Krasnyanskiy/jrsh/releases/download/v2.0.4/jrsh-2.0.4-jar-with-dependencies.jar"

  def install
    libexec.install "bfg-1.12.3.jar"
    bin.install_symlink libexec/"jrsh.sh"
  end

  test do
    system "#{bin}/jrsh"
  end
end
DomT4 commented 9 years ago

Make sure your brew is up-to-date with brew update.

Krasnyanskiy commented 9 years ago

After update I got this error

$ brew install jrsh
==> Downloading https://github.com/Krasnyanskiy/jrsh/releases/download/v2.0.4/jrsh-2.0.4-jar-with-dependencies.jar
==> Downloading from https://s3.amazonaws.com/github-cloud/releases/27540930/a49364a4-29d6-11e5-82a2-44fa98af1423.jar?re
######################################################################## 100.0%
Warning: Cannot verify integrity of jrsh-2.0.4.jar
A checksum was not provided for this resource
For your reference the SHA256 is: 5b3417c6658281ee6db60c8c70aace2d827eeefcffdf4ad822fee4c1fad69596
Error: No such file or directory - bfg-1.12.3.jar
Krasnyanskiy commented 9 years ago

I fixed libexec.install and installed jrsh one more time.

==> Downloading https://github.com/Krasnyanskiy/jrsh/releases/download/v2.0.4/jrsh-2.0.4-jar-with-dependencies.jar
Already downloaded: /Library/Caches/Homebrew/jrsh-2.0.4.jar
Warning: Cannot verify integrity of jrsh-2.0.4.jar
A checksum was not provided for this resource
For your reference the SHA256 is: 5b3417c6658281ee6db60c8c70aace2d827eeefcffdf4ad822fee4c1fad69596
🍺  /usr/local/Cellar/jrsh/2.0.4: 2 files, 13M, built in 2 secondsv
Krasnyanskiy commented 9 years ago

But I still can not run the app

$ jrsh
-bash: jrsh: command not found
Krasnyanskiy commented 9 years ago

Hmmm... I made

brew create 'https://github.com/Krasnyanskiy/jrsh/releases/download/v2.0.4/jrsh-2.0.4.zip'
brew audit --strict jrsh
brew update
brew reinstall jrsh

And now it works fine.

Krasnyanskiy commented 9 years ago

Resolved.

Krasnyanskiy commented 9 years ago

Error: No available formula for jrsh Searching formulae... Searching taps...

DomT4 commented 9 years ago

Did you create the new formula in a branch and then brew update? You may need to check the branch out again if so.

Krasnyanskiy commented 9 years ago

Oh, how can I do it?

DomT4 commented 9 years ago

Any idea if you created the new formula in a branch or not?

Krasnyanskiy commented 9 years ago

Yes, I guess I changed it.

Krasnyanskiy commented 9 years ago

So, I need to make brew install ... again, right?

DomT4 commented 9 years ago

Unless you've uninstalled it, the installation should still be there.

Krasnyanskiy commented 9 years ago

I've cleaned up all brew stuff and tried to reinstall the app. Here is what I got

$ brew install 'https://github.com/Krasnyanskiy/jrsh/releases/download/v2.0.4/jrsh-2.0.4.zip'
######################################################################## 100.0%
Error: uninitialized constant Formulary::FormulaNamespace3d9081e5aaefaee72d78da84dd674461::PK
Please report this bug:
    https://git.io/brew-troubleshooting
/Library/Caches/Homebrew/Formula/jrsh-2.0.4.zip:1:in `load_formula'
/usr/local/Library/Homebrew/formulary.rb:21:in `module_eval'
/usr/local/Library/Homebrew/formulary.rb:21:in `load_formula'
/usr/local/Library/Homebrew/formulary.rb:78:in `load_file'
/usr/local/Library/Homebrew/formulary.rb:128:in `load_file'
/usr/local/Library/Homebrew/formulary.rb:69:in `klass'
/usr/local/Library/Homebrew/formulary.rb:65:in `get_formula'
/usr/local/Library/Homebrew/formulary.rb:170:in `factory'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `block in formulae'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `map'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `formulae'
/usr/local/Library/Homebrew/cmd/install.rb:41:in `install'
/usr/local/Library/brew.rb:124:in `<main>'
Krasnyanskiy commented 9 years ago

Seems I uninstalled it

$ brew uninstall jrsh
Error: No such keg: /usr/local/Cellar/jrsh
DomT4 commented 9 years ago

You'll need to re-install it from the formula you created.

Krasnyanskiy commented 9 years ago

How can I do it? Could you tell me please what command should I use?

Krasnyanskiy commented 9 years ago

And I've noticed that I can't find the formula: http://brewformulas.org/search?utf8=%E2%9C%93&search%5Bterm%5D=jrsh&commit=Search

DomT4 commented 9 years ago

brewformulas will only list official formulae, not user-generated ones that haven't been merged into the core.

You'll need to check out whichever branch you created the formula in, and then brew install jrsh again. You can see which branches exist by doing cd $(brew --prefix) && git branch.

Krasnyanskiy commented 9 years ago

Ok, now it works. But other people could not install it. I made pull request with my formula jrsh.rb.

DomT4 commented 9 years ago

Thanks. Will let the test-bot review the submission, Closing here.

Krasnyanskiy commented 9 years ago

Ok, thanks.