• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to a resource inside the JAR, URI not hierarchical?  RSS feed

 
Josh Bern
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people, I'm new and this forum seems active!
I'm using NetBeans IDE and my directory structure looks like this:


I tried writing to a text file in the jar, can you folks see what's causing the exception in the command prompt when the following class is run in console like: java -jar "mypath/myjar.jar"? Thanks!


Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't write data into an existing jar file to my knowledge. You can however write it to a plain file and then make it a jar (zip) file.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the JavaRanch.
 
Josh Bern
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yo Wouter Out, thanks. Ok say I want to store simple text data inbetween runs, is my best option to store a text file in the same directory as the JAR? I'd love to bake it in somehow, but it's not worth it if it's too complicated.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea that is probably the easiest solution.

Btw it's Wouter Oet but please just call me Wouter.
 
Josh Bern
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm unsure how to make the text file appear in the dist folder besides the jar and how to write to it when the jar is run. I changed the path to this:



...and draged the text file to the dist folder by the jar. I type this in the command prompt:

C:\Documents and Settings\myName>java -jar "C:\Documents and Settings\myName\My Do
cuments\NetBeansProjects\myProject\dist\myjar.jar"


//When about to read in the file, not writing yet, this error materializes:
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at MyMain.main(QuestionMain.java:27)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!