Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

java jar ebuild - certain files in wrong folder [solved]

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
18 posts • Page 1 of 1
Author
Message
g047
n00b
n00b
User avatar
Posts: 23
Joined: Mon Aug 22, 2022 9:32 pm

java jar ebuild - certain files in wrong folder [solved]

  • Quote

Post by g047 » Sun Jul 14, 2024 3:01 pm

I'm trying to make a simple ebuild for a game named Unciv where I just retrieve the binary .jar.

The corresponding files get installed in the correct directories and everything launches fine, however files like save files or the game settings will be saved in my local repo at /var/db/repos/local/games-strategy/unciv-bin.

If possible via the ebuild, How do I make sure in-game created files are made so in a custom directory like /home/user/.local/share/unciv?

The ebuild in question can be seen here

Hopefully I've been clear, I'm still learning.

Thank you
Last edited by g047 on Wed Jul 17, 2024 8:17 am, edited 1 time in total.
Top
lars_the_bear
Guru
Guru
Posts: 537
Joined: Wed Jun 05, 2024 7:04 am

Re: java jar ebuild - certain files in wrong folder

  • Quote

Post by lars_the_bear » Sun Jul 14, 2024 4:32 pm

It seems to me that this program just saves in the current working directory. I don't think it will necessarily save in /var/db/repos... -- perhaps that's just where the program gets launched?

This seems like a fault in the program itself to me. If you can't fix it, perhaps you need to do something more than 'java -jar xxx.jar' to start it? I would use a wrapper script to create and change to a suitable directory, before launching the JVM.

BR, Lars.
Top
g047
n00b
n00b
User avatar
Posts: 23
Joined: Mon Aug 22, 2022 9:32 pm

Re: java jar ebuild - certain files in wrong folder

  • Quote

Post by g047 » Sun Jul 14, 2024 7:00 pm

lars_the_bear wrote:It seems to me that this program just saves in the current working directory. I don't think it will necessarily save in /var/db/repos... -- perhaps that's just where the program gets launched?
Oh darn you're right! :oops:
I can work with that and create a wrapper I guess, thanks.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3530
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Sun Jul 14, 2024 7:12 pm

You're both wrong. /var/db/repos is where the ebuild resides, not where the program is launched from. It must be launched at worst in the current user's home directory.


@g047 let me see your ebuild. In the mean time you can see this one: https://github.com/logrusx/gentoo/tree/ ... eplane-bin

Best Regards,
Georgi
Top
lars_the_bear
Guru
Guru
Posts: 537
Joined: Wed Jun 05, 2024 7:04 am

  • Quote

Post by lars_the_bear » Mon Jul 15, 2024 7:04 am

logrusx wrote:You're both wrong. /var/db/repos is where the ebuild resides, not where the program is launched from. It must be launched at worst in the current user's home directory.
This program, Unciv, writes in the CWD. I checked in the source. I presume that /var/db/repos just happened to be the CWD when testing the .ebuild.

BR, Lars.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3530
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Mon Jul 15, 2024 8:26 am

lars_the_bear wrote:I presume that /var/db/repos just happened to be the CWD when testing the .ebuild.
The ebuild is a bash script which is executed in a special environment. Portage creates that environment. It doesn't run in /var/db/repos. The closest is PORTAGE_TEMPDIR, but then it's portage that runs inside it, not the program. That's just wrong assumption OP made.

The program cannot be run anywhere outside the user's home directory, unless run manually from the command line. Even then it may terminate because of lack of permissions. A user may have permissions to chdir into a directory but not create files inside it.

In the case when a program is run from a .desktop file, then there are certain variables that can be set, but it they aren't the CWD is user's home.

Here's the specification: https://specifications.freedesktop.org/ ... atest.html

There's a key Path but I'm not sure which variables should be used to populate that key.

Best Regards,
Georgi
Top
lars_the_bear
Guru
Guru
Posts: 537
Joined: Wed Jun 05, 2024 7:04 am

  • Quote

Post by lars_the_bear » Mon Jul 15, 2024 10:04 am

logrusx wrote:
lars_the_bear wrote:I presume that /var/db/repos just happened to be the CWD when testing the .ebuild.
The ebuild is a bash script which is executed in a special environment. Portage creates that environment. It doesn't run in /var/db/repos. The closest is PORTAGE_TEMPDIR, but then it's portage that runs inside it, not the program. That's just wrong assumption OP made.
I wouldn't presume to speak for the OP, but I'm guessing he/she ran 'emerge my_thing' in the same directory as the .ebuild file, and then ran 'java -jar /path/to/my_thing.jar' to test it. Presumably as root (?).

But I'm just guessing. I can't think of any other reason why the program would write into /var/db/repos...

Personally, I'm not keen on Java programs writing to the CWD. But this particular program seems (?) mostly to be targetting Android, where this is relatively common practice. On Android, the launcher framework (as I recall) sets the CWD to some app-specific writeable directory (used to be /data/data/my.package/files, but I've no idea what it is now).

On the desktop, Java applications ought to provide a way to configure where configuration/status/etc gets written. Maybe a JVM property or an environment variable. It's hard to do this in a platform-neutral way.

BR, Lars.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3530
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Mon Jul 15, 2024 10:09 am

lars_the_bear wrote: I wouldn't presume to speak for the OP, but I'm guessing he/she ran 'emerge my_thing' in the same directory as the .ebuild file
As I said, ebuilds are run in a special environment, so it doesn't matter from which directory you run emerge.
lars_the_bear wrote:, and then ran 'java -jar /path/to/my_thing.jar' to test it. Presumably as root (?).
That's not testing the ebuild, that's running the program itself.

And again, running emerge has nothing to do with running the program. You can emerge a package and never run it.

Best Regards,
Georgi
Top
lars_the_bear
Guru
Guru
Posts: 537
Joined: Wed Jun 05, 2024 7:04 am

  • Quote

Post by lars_the_bear » Mon Jul 15, 2024 10:22 am

logrusx wrote: That's not testing the ebuild, that's running the program itself.
It's testing that the ebuild resulted in an installation in which the program can be run. But that's just a matter of semantics, isn't it?

BR, Lars.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3530
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Mon Jul 15, 2024 11:35 am

lars_the_bear wrote:
logrusx wrote: That's not testing the ebuild, that's running the program itself.
It's testing that the ebuild resulted in an installation in which the program can be run. But that's just a matter of semantics, isn't it?

BR, Lars.
I think I got what you meant, I should have misunderstood it in the beginning. OP is probably testing the program while still in /var/db/repos as root, is that what you meant? I was just caught up in portage terminology and stuff.

Best Regards,
Georgi
Top
lars_the_bear
Guru
Guru
Posts: 537
Joined: Wed Jun 05, 2024 7:04 am

  • Quote

Post by lars_the_bear » Mon Jul 15, 2024 11:42 am

logrusx wrote:OP is probably testing the program while still in /var/db/repos as root, is that what you meant? I was just caught up in portage terminology and stuff.
That was my guess, yes. But my guesses have been known to be wrong ;)

Local file storage is a pain in Java. The Java bytecode is notionally platform-agnostic, but it doesn't abstract the filesystem. The problem in this case is not with Gentoo/Portage, I think, but in the way the app's developers assume they'll always be able to write to the CWD (and that it will be appropriate to do so). Android is the only platform I know where that's the case.

BR, Lars.
Top
g047
n00b
n00b
User avatar
Posts: 23
Joined: Mon Aug 22, 2022 9:32 pm

  • Quote

Post by g047 » Wed Jul 17, 2024 8:16 am

So yeah, the corresponding save files were indeed stored in whatever location I launched the program from, I used pkg_postinst() to make sure the program will be launched from the directory I want, and now it works as intended, even if it feels a bit hacky :roll:

Anyway, thanks for the help
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3530
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Wed Jul 17, 2024 9:09 am

g047 wrote:I used pkg_postinst() to make sure the program will be launched from the directory I want
You should not launch the program in the ebuild. Please show us your ebuild, there might be better ways to do what you've done.

Best Regards,
Georgi
Top
Hu
Administrator
Administrator
Posts: 24386
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Wed Jul 17, 2024 2:27 pm

From the information so far, I would solve this by using src_install to write to $D a wrapper program. The wrapper could look like this (untested):

Code: Select all

#!/bin/sh

set -eu

mkdir -m700 -p ~/.local ~/.local/share ~/.local/share/unciv
cd ~/.local/share/unciv
exec java -jar /path/to/unciv.jar
Use of -p tells mkdir that it is not an error for the directory to exist. Each layer is enumerated, since -m applies only to the directories created explicitly. Customize that java invocation as needed.
Top
g047
n00b
n00b
User avatar
Posts: 23
Joined: Mon Aug 22, 2022 9:32 pm

  • Quote

Post by g047 » Thu Jul 18, 2024 12:59 pm

logrusx wrote: You should not launch the program in the ebuild. Please show us your ebuild, there might be better ways to do what you've done.

Best Regards,
Georgi
Sure, take a look https://bpa.st/W6RQ
But I'm not launching the program from the ebuild itself afaik

For reference, the original unciv launcher in /usr/bin/unciv is

Code: Select all

#!/bin/bash
gjl_package=unciv-bin
gjl_jar="unciv-bin.jar"
source /usr/share/java-config-2/launcher/launcher.ba
@Hu
This does seem as a more correct approach as i created the corresponding folders manually.
Top
logrusx
Advocate
Advocate
User avatar
Posts: 3530
Joined: Thu Feb 22, 2018 2:29 pm

  • Quote

Post by logrusx » Thu Jul 18, 2024 2:08 pm

Have you noticed there's a linuxFilesForJar.zip in the relase files with a ready made .desktop file as well as bash script that does exactly what you want to do?

Otherwise you're doing some thing that are not clear to me and I would argue they are not necessary, but to do that I have to roll up my sleeves and test it, which I don't feel like doing right now.

Best Regards,
Georgi
Top
g047
n00b
n00b
User avatar
Posts: 23
Joined: Mon Aug 22, 2022 9:32 pm

  • Quote

Post by g047 » Thu Jul 18, 2024 4:31 pm

logrusx wrote:Have you noticed there's a linuxFilesForJar.zip in the relase files with a ready made .desktop file as well as bash script that does exactly what you want to do?
Georgi
I did not notice that, I'll update my ebuild this weekend so it will use the bash script, thanks.
Top
charles17
Advocate
Advocate
Posts: 3686
Joined: Sun Mar 02, 2008 3:20 pm

  • Quote

Post by charles17 » Fri Jul 19, 2024 6:54 am

g047 wrote:Sure, take a look https://bpa.st/W6RQ
But I'm not launching the program from the ebuild itself afaik

For reference, the original unciv launcher in /usr/bin/unciv is

Code: Select all

#!/bin/bash
gjl_package=unciv-bin
gjl_jar="unciv-bin.jar"
source /usr/share/java-config-2/launcher/launcher.ba
For a launcher look for java-pkg_dolauncher on https://devmanual.gentoo.org/eclass-ref ... -2.eclass/
Find examples runnning qgrep java-pkg_dolauncher
Top
Post Reply

18 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic