Reputation: 77
I'm developing on Google Glass with the mirror API. I am building off the Java starter project [https://www.youtube.com/watch?v=w0WxkIEPJeQ][1].
In my app, I want one of my timeline cards to have html with an image tag whose 'src' attribute is referencing a local file on my machine. I'm doing this for testing purposes. I placed the image inside my project folder under root_proj/img/image1.jpg. So that timeline card looks like
<article>
<figure>
<img src='img/image1.jpg'>
</figure>
</article>
However, it seems it can't find the file. So I thought maybe I need to build the path starting from the root directory of the jetty server. Jetty was installed as a plug-in to Eclipse per the instructions for the starter project. However, I don't know where the root dir is for the jetty server.
Is my thinking correct? If not, how can I display local images on my Glass when doing local development?
Upvotes: 0
Views: 572
Reputation: 1570
I would suggest starting by placing your images in the src/main/webapp/static/images folder of the project.
You can then play around with the image references in index.jsp (src/main/webapp) to make sure your images load correctly (try changing the cat image reference in the img tag with class="button-icon" to image1.jpg, for example).
Moving on, you may want to import WebUtil (com.google.glassware.WebUtil) in your new servlets and use it to get the base URL of your app.
Here is code from the index.jsp file of the Quickstart project (located in src/main/webapp):
String appBaseUrl = WebUtil.buildUrl(request, "/");
You can now reference this to load images in the static/images folder, i.e. the following:
value="<%= appBaseUrl + "static/images/chipotle-tube-640x360.jpg" %>"
Upvotes: 0