title: Accessing files and images from jar files
body: <p>I've been running into issues when trying to accessing files and images in a jar file. The program works as expected before being made into a jar file. I have created a Resources folder used ClassLoader but still getting an error on command line when trying to run the jar file it works but not all the information shows.</p>
  
  <p>The type has to be a File so that the databaseReader can read it.</p>
  
  <p><strong>Error message</strong></p>
  
  <pre><code>java.io.FileNotFoundException: file:\C:\Users\Nicholas\IdeaProjects\MirrorMe\out\artifacts\MirrorMe_jar\MirrorMe.jar!\GeoLite2-City.mmdb (The filename, directory name, or volume label syntax is incorrect)
      at java.io.RandomAccessFile.open0(Native Method)
      at java.io.RandomAccessFile.open(Unknown Source)
      at java.io.RandomAccessFile.&lt;init&gt;(Unknown Source)
      at com.maxmind.db.BufferHolder.&lt;init&gt;(BufferHolder.java:19)
      at com.maxmind.db.Reader.&lt;init&gt;(Reader.java:116)
      at com.maxmind.geoip2.DatabaseReader.&lt;init&gt;(DatabaseReader.java:35)
      at com.maxmind.geoip2.DatabaseReader.&lt;init&gt;(DatabaseReader.java:23)
      at com.maxmind.geoip2.DatabaseReader$Builder.build(DatabaseReader.java:129)
      at sample.LocateMyCity.&lt;init&gt;(LocateMyCity.java:60)
      at sample.WeatherToday.getPersonLocationId(WeatherToday.java:102)
      at sample.WeatherToday.&lt;init&gt;(WeatherToday.java:126)
      at sample.Main.start(Main.java:37)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p><strong>Full Code</strong></p>
  
  <pre><code>public class LocateMyCity {
  
  private String myCityLocation;
  
  private String country;
  
  public String getCountry() {
      return country;
  }
  
  public String getmyCityLocation(){
      return myCityLocation;
  }
  
  public LocateMyCity() {
      try {
  
  
          ClassLoader classLoader = getClass().getClassLoader();
          File database = new File(classLoader.getResource("GeoLite2-City.mmdb").getFile());
  
          URL whatismyip = new URL("http://checkip.amazonaws.com");
          BufferedReader in = new BufferedReader(new InputStreamReader(
                  whatismyip.openStream()));
  
          String ip = in.readLine(); //you get the IP as a String
          System.out.println(ip);
  
          // This creates the DatabaseReader object, which should be reused across
          // lookups.
          DatabaseReader reader = new DatabaseReader.Builder(database).build();
  
          InetAddress ipAddress = InetAddress.getByName(ip);
  
          // Replace "city" with the appropriate method for your database, e.g.,
          // "country".
          CityResponse response = reader.city(ipAddress);
  
          City city = response.getCity();
          System.out.println(city.getName()); // 'Minneapolis'
          this.myCityLocation = city.getName();
  
          Country country = response.getCountry();
          System.out.println(country.getIsoCode());            // 'GB'
          this.country = country.getIsoCode();
  
          System.out.println(country.getName());               // 'United Kindom'
  
      }catch (Exception e){
          e.printStackTrace();
          System.out.println("Tracing IP E");
      }
  }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WIYz7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WIYz7.png" alt="Inside jar file"></a>
  Thanks in advance.</p>