#Font loadng from ttf creates exception when running on Ubuntu (HELP STILL NEEDED)

1 messages · Page 1 of 1 (latest)

fair tigerBOT
#

<@&987246399047479336> please have a look, thanks.

fair tigerBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

rigid totem
#

share the setup for ur resource folder

tropic fern
#

so i decompiled it and saw that theres no recourses folder
spooky ghost story

#

i assume this is an uberjar?

rigid totem
#

why are u "decompiling" the jar? i doubt ur decompiler shows anything but code

#

open the jar with a zip program

#

like winrar, 7zip. or rename to .zip, then u can also doublecheck enter it in windows

#

Also share the artifact settings please. maybe u specifically selected only binaries

#

lol

#

move ur resources into ur resource folder

#

where they belong

#

what do u mean

#

i dont follow what ur saying

#

u just said they are elsewhere didn't u

#

are they in ur final jar now or not? have u opened ur jar with a zip viewer?

#

that's correct. the resource folder is not supposed to be in the jar,only its contents

#

so ur resources are in ur jar? then everything is correct

#

yes

#

what are u talking about

hardy dew
#

seems like a problem with your code instead of compiling problems

#

first lol why do you cast an integer to float?

#

instead of 16f

#

also (int) (float) 16???

#

I have it like this, only difference I see is that I am using try-with-resource

noble quartz
#

could it be the /

hardy dew
#

nah, thats needed for getResourceAsStream iirc

rigid totem
#

just debug the code

#

don't guess @nocturne lichen

#

put in some stuff to explore what's going on

#

check whether the stream returned null or not

#

if its null, there's an issue reading the file

#

if not null, there's an issue with the files content

#

and so on

hardy dew
#

you know what a debugger is?

noble quartz
#

its better that u log and learn to debug. Then u can actually follow what is happening and see what's going on while the program is running

#

if your not really familiar with debugging, its no shame. But please say so

#

no worries on that, just put it high on your to-learn list. For now , did u ever by accident place a red dot before a code line before ?

#

if u place such a dot on a line, the program will 'pause' at that point and u can see what's in all the variables ( u can do alot more , but that's one of the first things u will use it for )

#

(do not forget to start it in debug mode aswell)

#

place it on the Font font line

#

is it still the io error or another one ?

hardy dew
#

seems like some dependency got a signed jar or smth

noble quartz
#

is that ==null still in there ?

noble quartz
#

solution with 58 something @hardy dew ?

#

the exclude one

noble quartz
#
 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <minimizeJar>true</minimizeJar>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>
#

that one

hardy dew
#

that could work

#

you use maven right?

#

then yeah

noble quartz
#

can't harm to try

hardy dew
#

but are you even running a jar or running in intellij directly?

#

how are you running your application?

#

ok and you creating the jar with mvn package?

#

wdym

#

then I have no idea

#

no idea helping with how to fix your security exception

ashen inlet
#

Try recloning your repository

fair tigerBOT
#

Activities have been reset.

fair tigerBOT
#

Activities have been reset.

tropic fern
#

@nocturne lichen Can you maybe share your project in a way where we can run it?

hardy dew
#

I dont see the reason not using maven package for packaging it to a jar

#

with mvn package?

#

show your pom.xml

#

you are missing the configuration stuff

#

you first need <packaging>jar</packaging>

#

and this iirc for adding dependencies into the jar:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>com.example.MainClass</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

replace com.example.MainClass with your main class

#

I think in a <plugins> </plugins>

#

but not sure

noble quartz
#

group tag is correct

hardy dew
#

sorry in <build> </build> inside that a <plugins> </plugins>

noble quartz
#
<build>
  <plugins>

  </plugins>
</build>
hardy dew
# hardy dew and this iirc for adding dependencies into the jar: ```xml <plugin> ...

you might instead use this:

<build>
  <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.2.2</version>
          <configuration>
              <archive>
                  <manifest>
                      <addClasspath>true</addClasspath>
                      <mainClass>...</mainClass>
                  </manifest>
              </archive>
          </configuration>
      </plugin>
      
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    // maybe add some configurations, for example excluding signed stuff
                </execution>
            </executions>
          </plugin>
  </plugins>
</build>
noble quartz
#

check your pom, that snapshot thing is normally in there

#

check <version>

hardy dew
#

wdym

#

there is a field for main class

#

in the configuration

#

of the first plugin

noble quartz
#

do u have any tests in your project btw ?

#

unit testing etc ?

#

anything in your tests that can fail ? if u haven't got any there's no need, but if u got tests that may fail u can skip those while compiling, else maven won't compile

hardy dew
#

show the error

noble quartz
#

hold on, this is progress

hardy dew
#

seems like a problem with your .ttf file

#

because its not null if I see correctly

#

also dont use print statements for debugging

noble quartz
#

thigns can run in an ide even when malconfigured

#

not necessary

#

u got 2 stactrackes

#

u got e.printStackTrace aswell so u need to figure out if its going in the exeption ( and even failing there )

#

i know, but its acting normally as u programd it

#

it looks like it fails, then u forced a secondary print, and then u return ( what i assume is normal ) font

#

so it shouldnt even stop

#

any reason why the t/c is a float and the other is not ?

hardy dew
#

btw line 67 in ImageGen is Font font = Font.createFont(...) right?

#

javadocs for that method saying that:

IOException - if the fontStream cannot be completely read.

noble quartz
#

System.out.println(e.getClass());

#

don't guess

hardy dew
#

just use a debugger

noble quartz
#

OP said he never used one before ( a few hours ealier )

hardy dew
#

yeah and whats wrong with that?

#

now is the time learning it

noble quartz
#

nothing, just needs some more guidance on how-to 😉

hardy dew
#

there will always be a first time

noble quartz
#

yep

#

where are u deploying that jar / war then ?

#

u said it's the VM and it works on your computer, so where are u running it so it fails ?

hardy dew
#

what vm?

noble quartz
#

what's on the vm then ? a server ?

hardy dew
#

give information about your vm

noble quartz
#

can u be clear please, what's running on it ? a server or not ?

#

so u need a war ?

hardy dew
#

I dont see why the Font#createFont should fail though?

noble quartz
#

that wont, it could explain why its not finding the files

hardy dew
#

ah ok

#

its null

#

why dont you say it

#

...

#

why does it say false though

#

?

#

you do inputstream==null

#

which prints false

#

which means its not null

#

yeah look at it peepo_heart

#

yeah which prints false

#

so its not null

#

or the printing is coming from somewhere else

noble quartz
#

(there is a false before the 1st stactrace)

hardy dew
#

based on the information i have its not

#

but for that just use an debugger

#

it makes it way easier

#

no need for guessing

noble quartz
#

(also why u got that screen open, change it to the correct format try-with-resources )

#

@nocturne lichen what happens when u double click on that font file in windows ?

hardy dew
#

try this

#

yeah

#

before so I think like this:
java -arg -jar jarfile.jar

#

where you replace -arg with the argument

#

yeah should work

#

hm

#

but you said the code works on windows right?

noble quartz
#

have u checked that that file is correct ?

hardy dew
noble quartz
#

true, if his catch wasnt triggerd

hardy dew
#

so you mean using this new BufferedInputStream(new FileInputStream(FONT_PATH_TELEGRAFICO)); for creating the font stream?

#

btw using a debugger would be really helpful in your case
based on the implementation the IOException is caused by some other exception, but we dont know which one
debugging would show which exception is causing it

#

try it why not

#

so you are trying to run the jar on ubuntu right? can you tell me which ubuntu so I can make a virtual machine and debug the jar

#

btw nice pronouns on discord pepekek

#

yeah true the class is enough no need sharing the whole project, but it doesnt need to give same results

#

what about the server so I can already install the distro

#

what about the server???

#

@nocturne lichen

#

also why are you using java 18? kinda weird version

#

most use either last lts (17), any lts or newest (20)

#

running on my wsl is working fine

#

so I need the real server specs

#

@nocturne lichen

#

idk you said smth about a vps

#

it should provide that information

#

idk which vps are you using

#

yeah? should I guess that?

#

and now?

#

we knew before

#

we need more information why the loading fails

#

because its working on windows but not on your vm

#

but I need information about your vm

#

to replicate that scenario

#

because on my wsl Ubuntu its working fine

#

I dont know and cant tell without knowing the vps

#

just google

#

vps-name get vm os information or stuff like that

#

yeah the linux distro the vm is using

#

etc

#

there should be a linux command for that as well if you got access to terminal

#

thanks

#

now give me some time

#

its a server image right? so no gui version

echo void
#

I think you have to use getResourceAsStream from a ClassLoader not a .class.

hardy dew
#

but getResourceAsStream doesnt seem to be the problem

#

because on windows the code works fine

#

but on linux the Font#createFont throws

#

and InputStream is not null

echo void
#

Google what I just said, there's a history of this problem.

hardy dew
#

and why do you think its related to this?

echo void
#

Because I've run into it before.

hardy dew
#

when trying to create a Font from a ttf on linux?

echo void
#

just try getClassLoader().getResourceAsStream() and it should work.

#

No wait. Maybe it was System classLoader, yea. try that.

hardy dew
#

I think he already tried that earlier and didnt work

echo void
#

I don't see where he tried that. It is the answer though.

#

getSystemResourceAsStream I believe

hardy dew
#

@nocturne lichen I cant really replicate your scenario, it runs fine without any exception etc

#

on Ubuntu 20.04.6 (focal server)
with java 17
using this code:

public class ImageGen {

    public static Font loadMinecraftFont() {
        try {
            InputStream inputStream = ImageGen.class.getResourceAsStream("/minecraft.ttf");
            Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
            return font.deriveFont(16F);
        } catch (Exception e) {
            e.printStackTrace();
            return new Font(Font.MONOSPACED, Font.PLAIN, 16);
        }
    }
}

public class Main {
    public static void main(String[] args) {
        System.getProperties().list(System.out);
        System.out.println();

        Font font = ImageGen.loadMinecraftFont();
        System.out.println(font);
    }
}
#
-- listing properties --
java.specification.version=17
sun.management.compiler=HotSpot 64-Bit Tiered Compilers
sun.jnu.encoding=UTF-8
java.runtime.version=17.0.8+7-Ubuntu-120.04.2
java.class.path=/home/zushee/ZusheeFontError/IMnMHPLZWh
user.name=zushee
java.vm.vendor=Private Build
path.separator=:
sun.arch.data.model=64
os.version=5.4.0-156-generic
java.runtime.name=OpenJDK Runtime Environment
file.encoding=UTF-8
java.vendor.url=Unknown
java.vm.name=OpenJDK 64-Bit Server VM
java.vm.specification.version=17
os.name=Linux
sun.java.launcher=SUN_STANDARD
user.country=US
sun.boot.library.path=/usr/lib/jvm/java-17-openjdk-amd64/lib
sun.java.command=com.zushee.Main
java.vendor.url.bug=Unknown
java.io.tmpdir=/tmp
jdk.debug=release
sun.cpu.endian=little
java.version=17.0.8
user.home=/home/zushee
user.dir=/home/zushee/ZusheeFontError/xf6z6k2F2R
os.arch=amd64
user.language=en
java.specification.vendor=Oracle Corporation
java.vm.specification.name=Java Virtual Machine Specification
java.version.date=2023-07-18
java.home=/usr/lib/jvm/java-17-openjdk-amd64
file.separator=/
java.vm.compressedOopsMode=32-bit
native.encoding=UTF-8
line.separator=

java.library.path=/usr/java/packages/lib:/usr/lib/x86_6...
java.vm.info=mixed mode, sharing
java.vm.specification.vendor=Oracle Corporation
java.specification.name=Java Platform API Specification
java.vendor=Private Build
java.vm.version=17.0.8+7-Ubuntu-120.04.2
sun.io.unicode.encoding=UnicodeLittle
java.class.version=61.0

java.awt.Font[family=Minecraftia,name=Minecraftia 2.0,style=plain,size=16]

Process finished with exit code 0
echo void
#

It's because Intellij munges the classloader to make it work. Don't build with your IDE folks. Delegate to maven or gradle for builds and you'll still have hair when you're 40.

hardy dew
#

he didnt build with ide though

#

he is using maven

#

but true I notice that my test is building with ide

#

let me test with maven in a sec

hardy dew
#

now I tried with mvn package + scp transfer file to ubuntu server + java -jar jarfile.jar and it worked without any problems

#

with this pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.zushee</groupId>
    <artifactId>ZusheeFontError</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.zushee.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
#

ah ok

#

then try his suggestion

#

ok

#

I could replicate your scenario

#

maybe share your .jar

#

maybe its specific to your jar

#

so I can test with the exact code

tulip fernBOT
#
public static InputStream getSystemResourceAsStream(
  String name
)

Open for reading, a resource of the specified name from the search path used to load classes. This method locates the resource through the system class loader (see #getSystemClassLoader()).

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is

hardy dew
#

it should

#

its a static method

noble quartz
#

gets. ?

hardy dew
#

ClassLoader.getSystemResourceAsStream

#

what about linux?

#

@echo void see

#

yeah because you return a different font on exception

#

can you share your jar file pls

#

so I can test it

#

its a bot

#

it should work if I run it

#

true, but the jar contains the bot token right?

#

so it should still work if I run it and you type the command

#

but its ok if you wont share the bot token/jar file with me

noble quartz
#

at this point i would defo share the jar. He already put alot of effort in to try things

echo void
#

Thread.currentThread().getContextClassLoader()

hardy dew
#

.

echo void
#

Does he have slash prefix?

hardy dew
noble quartz
#

he's got a slash prefix

hardy dew
#

as I told you the resource is not null

#

meaning its not a getResourceAsStream issue

echo void
#

It's his runtime

#

You are not getting a classloader than can see your resources

hardy dew
echo void
#

Similar things happen when you run in containers

noble quartz
#

the resource loads no problem @echo void

echo void
#

So he is getting something back from getResource?

#

and not null?

hardy dew
#

yeah I told you already

#

20 times

echo void
#

I'm not reading this entire chat log sorry.

noble quartz
#

the error that's returning is from the font , and they made it throw io

hardy dew
echo void
#

He can't debug into his runtime container I bet

hardy dew
echo void
#

So use the old system prints

noble quartz
#

he did, that's why we know its not null

hardy dew
#

can we try tomorrow if you didnt fixed it until then?
its already late for me and got some appointment tomorrow early

#

what time is it for you rn

echo void
#

It's early here!

hardy dew
#

ok see ya tomorrow

echo void
#

I would try to print out all resources it can see.

hardy dew
fair tigerBOT
#

Font loadng from ttf creates exception when running on Ubuntu

#

Changed the title to Font loadng from ttf creates exception when running on Ubuntu.

#

Activities have been reset.

hardy dew
#

You didn’t understand what I was saying

#

The exception you get, gets thrown in the catch block of the createFont0 method (look at your stacktrace), that means that some other exception needs to get thrown inside the try block of the createFont0 method, this exception gets “shaded“ by the IOException you get at the end, check the screenshot of the snippet

#

And I would use a debugger to see the actual exception that gets thrown

#

But you don’t seem to know how to and I can’t reproduce the error on my end

#

That’s why you need to debug the Linux process

echo void
#

Did you edit this ttf file on windows and then save it?

hardy dew
#

Not sure if that’s a problem

#

I tried it on my Linux wsl

#

And on an Ubuntu server

#

And both worked fine

#

I will look tomorrow

#

Really need to sleep now

echo void
#

Says you might have to install the font on the machine first

echo void
#

Maybe Font.createFonts is what you want. The font file you are trying to create maybe has multiple fonts in it (variants?)

#

Otherwise you need to look at Throwable.cause on that exception you are getting. (or the chain of causes.) It shows you getting past temp file creation/deletion and if you look at the catch block at the bottom of createFont0 it weeds out Font format and previous IOExceptions.

#

Sorry, its not going to have info on the cause because its hidden.

hardy dew
#

Already gave all that information

hardy dew
#

Makes no sense to guess here

#

Just check the actual cause with a debugger

hardy dew
#

@nocturne lichen I have time now, just need to tell me when you have time for this

hardy dew
#

ok cat_thumbs_up

fair tigerBOT
#

Activities have been reset.

fair tigerBOT
#

Font loadng from ttf creates exception when running on Ubuntu (HELP STILL NEEDED)

#

Changed the title to Font loadng from ttf creates exception when running on Ubuntu (HELP STILL NEEDED).

hardy dew
#

kinda hopeless without a minimal reproducible example

#

Code works also on ubuntu but not on my version somehow
I tried both on wsl ubuntu and the same ubuntu you are using

#

yeah

hardy dew
#

this one

#

so I couldnt reproduce your issue

#

which makes it kinda impossible to help

#

but we can do vc if you want later

#

and try on your machine

#

to debug

#

uses Ubuntu 20.04.6 LTS as well

#

yeah try that if its ok for you

hardy dew
#

hi

hardy dew
#

ok

#

wipe os ig

#

and try again

hardy dew
#

and?

fair tigerBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

hardy dew
#

hi

#

with wiped os?