1

I am working on a full-stack assignment. I have developed my backend REST Apis using spark java and maven. Now I am clueless about how to code the html and js files contacting the REST apis so as to develop a full stack application

I tried placing sample htmls under the root of the app and also under

src/main/resources/public/index.html

But it throws

404 not found

I have seen tutorials relating to spark java application with angular js https://blog.openshift.com/developing-single-page-web-applications-using-java-8-spark-mongodb-and-angularjs but I neither know Angular JS.

So can someone help me in understanding or guiding me to a resource on how to run html/js/css files with spark java application?

Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
  • 1
    see https://stackoverflow.com/questions/28125886/where-to-put-static-files-for-spark-web-framework – Oleg Aug 13 '17 at 14:47

2 Answers2

0

You need to specify where the static files should be found. An example is:

Spark.staticFileLocation("/public");

This public is a directory in your classpath called public. If you are using Maven, then this translates to

src/main/resources/public/
Thomas Sundberg
  • 4,098
  • 3
  • 18
  • 25
0

You can get your /public folder path from your code. For example, you have your app structure as:

YourNiceAppFolder/Server.jar

YourNiceAppFolder/public

Just find your Server.jar file location and return path to /public folder. In this case, you shouldn't worry about building process(only about the relation between server.jar and public folder).

enter image description here See example here

Andrew
  • 479
  • 5
  • 15