Blog Archives
heroku cheat sheet quick start
#note requires java 8. add the ppa repo for oracle and install this if you dont have it already. check your local with: java -version
#create auth token for subsequent commands
heroku login
#from within a local git cloned app root, to create a new dyno
heroku create
#deploy
git push heroku master
#check if dyno is running
heroku ps:scale web=1
#shortcut to open the dyno. if you are running these in a remote SSH you will need to X11 forward for this to work
#or simply, just open the address indicated after you push
#this uri is also visible using the logs command below
heroku open
#tail logs for running dyno. refresh the browser while you are viewing the app to verify new log entries added
heroku logs --tail
#procfile declares what command is executed at start of app. this is likely web.
#for windows: this is different. see heroku docs and make Procfile.windows and use heroku -f Procfile.windows
https://devcenter.heroku.com/articles/procfile
#general note regarding the “free-ness” of heroku on your first app
“By default, your app is deployed on a free dyno. Free dynos will sleep after a half hour of inactivity and they can be active (receiving traffic) for no more than 18 hours a day before going to sleep. If a free dyno is sleeping, and it hasn’t exceeded the 18 hours, any web request will wake it. This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally”
#pom.xml specifies dependencies
#system.properties in the case of java determines version of java to use
#pull in dependencies to target/dependency and store this in pom.xml
mvn clean install
#to start heroku locally
heroku local web
#install add-ons
heroku addons:create papertrail
#list add-ons
heroku addons
#open add-on logs
heroku addons:open papertrail
#test a command on a one-off dyno, e.g. run bash in local dyno
heroku run bash
#set environment variables
heroku config:set ENERGY="20 GeV"
#view environment variables
heroku config
#show database info, e.g. postgres
heroku pg
#run tsql commands
heroku pg:psql
References:
https://devcenter.heroku.com/articles/getting-started-with-java
javac invalid target release maven ant intellij netbeans eclipse
You may see the following error when running maven or ant command or from intellij:
javac: invalid target release: 1.8
This occurs because you are running a build target for a version of java that you do not have set as your default in JAVA_HOME.
If you do not have java 8 installed, in ubuntu this is as simple as:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
This is similar in other flavors of linux, simply add the official oracle repo and install. Installation in Windows requires browsing to the JDK/JRE pages on Oracle and downloading/installing. Avoid OpenJDK. This is outside the context of this blog post, but you can google “openjdk vs oracle jdk performance” to learn more.
If you see this error in an IDE such as intellij, netbeans or eclipse, this can be fixed by setting the java compile in your Settings to Java 8. E.g. if the error above said 1.9, change this to Java 9.
If you are upgrading from 7 to 8, the last oracle install step when installing the package should set JAVA_HOME:
(ubuntu) sudo apt-get install oracle-java8-set-default
If the above install command or corresponding install script on your system does not work, to fix you can also manually set JAVA_HOME, such as:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
echo the current $JAVA_HOME and the new oracle java home should be alongside it.
In my scenario I actually ran the oracle provided install script but it failed to set the java home correctly so I still had to do this manually.
http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/#
How to Create a new Java Applet in Netbeans
First create a new project. Make sure you select “Java Application” not Desktop Application or other types.
On the left hand of the screen you should see “Source Packages” and your project name in lower case underneath. If you don’t see this in the little window on the left, expand the coffee icon with your project name.
Right click your package (mine is javafileuploader in the screenshot above) and select New->Java Class.
Make sure your new class is selected, and then referencing my code snippet below, import java.applet.* and java.awt.* then add new functions for “paint” and “init”.
(code snippet courtesy of ehow link in references)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javafileuploader; import java.applet.*; import java.awt.*; /** * * @author fedora */ public class NewClass extends Applet { int m_height, m_width; public void paint(Graphics m) { m.setColor(Color.black); for (int i=0; i<10; ++i)m.drawLine(m_width,m_height,i*m_width/10,0); } public void init() { m_width=getSize().width; m_height=getSize().height; setBackground(Color.green); } }
Once you have this typed/pasted in, select run->file and voila! you should see a little applet window appear with a green background and oblique lines. You’re now ready to begin. Enjoy!
References
ehow.comhttp://www.ehow.com/how_6210608_create-java-applet-netbeans.html
Android Launch Browser from App to handle external URLs
Upon googling for this one, I found some good relevant links on stack overflow as well as the android webview documentation, but no singular solution that tied everything together.
First, I created a custom WebViewClient class. Note that this is optional as you can do inline class declarations in this environment.
package com.example.testapp; import android.app.Activity; import android.content.Context; import android.net.Uri; import android.webkit.WebView; import android.webkit.WebViewClient; import android.content.Intent; public class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url != null &amp;&amp; url.startsWith('http://192.168.1.101')) { return false; } else { view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } } }
Then, in the main activity, use code within onCreate to support for multiple windows and to set the web view client to your own custom client.
package com.example.testapp; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.Menu; import android.webkit.WebView; import android.webkit.WebViewClient; import android.view.KeyEvent; import android.webkit.WebChromeClient; import android.net.Uri; public class MainActivity extends Activity { private WebView webView; @Override public void onCreate(Bundle savedInstanceState) { final Context context = this; super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportMultipleWindows(true); webView.setWebViewClient(new MyWebViewClient()); webView.loadUrl('http://192.168.1.1/login.aspx'); }
If you want to use an inline class declaration instead of defining a seperate mywebviewclient class, you can also use something like:
webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //etc, same code as above } });
If you have not already addressed the question of handling the android back button within your webview, the android documentation has a good quick simple code reference on how to accomplish this.
Enjoy. 🙂
References
StackOverflow, http://stackoverflow.com/questions/5979361/android-open-url-in-a-new-window-without-leaving-app
StackOverflow, http://stackoverflow.com/questions/7028258/launch-browser-from-within-app-how-do-you-get-back-to-the-app
Android Documentation, http://developer.android.com/reference/android/webkit/WebView.html