Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the JavaRanch.
 
Josh Bern
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic