title: Is it possible to use RestTemplate on desktop instead of Android?
body: <p>I encountered an error when I was trying to upload a file from my laptop to my server. </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NoClassDefFoundError: android/os/Build$VERSION</p>
  </blockquote>
  
  <p>I searched the error code and found an answer that suggesting I should run my code on an Android device, but what if I run my code on my laptop. Is it possible to create a RestTemplate standalone program running on desktop?</p>
  
  <p>server side code:</p>
  
  <pre><code>@RequestMapping(value="/upload", method=RequestMethod.POST)
  public String handleUpload(String filename, MultipartFile file) throws IOException {
      if(!file.isEmpty()) {
          File saveFile = new File(rootPath + "\\" + filename);
          saveFile.createNewFile();
  
          BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(saveFile));
  
          FileCopyUtils.copy(file.getInputStream(), bufferedOutputStream);
  
          bufferedOutputStream.close();
  
          return "uploaded successfully";
      } else {
          return "failed";
      }
  }
  </code></pre>
  
  <p>client side code:</p>
  
  <pre><code>public static void main( String[] args )
  {
      String url = UPLOAD_URL;  
      String filePath = PATH + "\\204375-106.jpg";  
  
      SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory();
  
      RestTemplate rest = new RestTemplate(httpRequestFactory);  
      FileSystemResource resource = new FileSystemResource(new File(filePath));  
      MultiValueMap&lt;String, Object&gt; param = new LinkedMultiValueMap&lt;String, Object&gt;();  
      param.add("file", resource);  
      param.add("filename", "204375-106.jpg");  
  
      String string = rest.postForObject(url, param, String.class);  
      System.out.println(string);
  }
  </code></pre>