#Font loadng from ttf creates exception when running on Ubuntu (HELP STILL NEEDED)
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
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.
share the setup for ur resource folder
so i decompiled it and saw that theres no recourses folder
spooky ghost story
i assume this is an uberjar?
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
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
could it be the /
nah, thats needed for getResourceAsStream iirc
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
you know what a debugger is?
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 ?
seems like some dependency got a signed jar or smth
is that ==null still in there ?
what?
<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
can't harm to try
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
Try recloning your repository
Activities have been reset.
Activities have been reset.
@nocturne lichen Can you maybe share your project in a way where we can run it?
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
group tag is correct
sorry in <build> </build> inside that a <plugins> </plugins>
<build>
<plugins>
</plugins>
</build>
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>
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
show the error
hold on, this is progress
seems like a problem with your .ttf file
because its not null if I see correctly
also dont use print statements for debugging
.
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 ?
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.
just use a debugger
OP said he never used one before ( a few hours ealier )
nothing, just needs some more guidance on how-to 😉
there will always be a first time
you tried
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 ?
what vm?
what's on the vm then ? a server ?
give information about your vm
can u be clear please, what's running on it ? a server or not ?
so u need a war ?
is it really needed?
I dont see why the Font#createFont should fail though?
that wont, it could explain why its not finding the files
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 
yeah which prints false
so its not null
or the printing is coming from somewhere else
(there is a false before the 1st stactrace)
based on the information i have its not
but for that just use an debugger
it makes it way easier
no need for guessing
(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 ?
On Linux, launching a JVM in a console and using it to access awt or swing components sometimes causes problem because the X11 support is not included. You should try using headless mode to launch the server.
https://javatechniques.com/blog/linux-x11-libraries-for-headless-mode/
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?
have u checked that that file is correct ?
no need if it works on windows
true, if his catch wasnt triggerd
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 
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
I think you have to use getResourceAsStream from a ClassLoader not a .class.
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
Google what I just said, there's a history of this problem.
and why do you think its related to this?
Because I've run into it before.
when trying to create a Font from a ttf on linux?
just try getClassLoader().getResourceAsStream() and it should work.
No wait. Maybe it was System classLoader, yea. try that.
I think he already tried that earlier and didnt work
I don't see where he tried that. It is the answer though.
getSystemResourceAsStream I believe
@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
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.
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
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
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
gets. ?
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
at this point i would defo share the jar. He already put alot of effort in to try things
Thread.currentThread().getContextClassLoader()
Does he have slash prefix?
It is the answer though.
how where you so sure
he's got a slash prefix
but the resource is NOT NULL
Similar things happen when you run in containers
the resource loads no problem @echo void
I'm not reading this entire chat log sorry.
the error that's returning is from the font , and they made it throw io
I answered it to your messages
He can't debug into his runtime container I bet
.
your respond:
Google what I just said, there's a history of this problem.
So use the old system prints
he did, that's why we know its not null
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
It's early here!
ok see ya tomorrow
I would try to print out all resources it can see.
let me try giving you the current state imo
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.
this is the implementation of the method that throws the IOException seen at the end
based on this I know that the cause is some other exception and to fix the problem I would have searched the original throwable that
gets catched here to see the reason why its failing
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
Did you edit this ttf file on windows and then save it?
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
You can look at the jvm code at that location
JDK main-line development https://openjdk.org/projects/jdk - openjdk/jdk
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.
Already gave all that information
Works on windows and for me on Linux just saying
Makes no sense to guess here
Just check the actual cause with a debugger
@nocturne lichen I have time now, just need to tell me when you have time for this
ok 
Activities have been reset.
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).
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
.
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
hi
and?
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 👍