I am trying to work with jshell of Java 9. So for that i installed the JDK 9 on my Mac, where i already had the JDK 8 installed.
All my projects, workspaces, Hadoop, Spark and dependent APIs are using JDK 8. So for the current scenario, i can not move all my projects to work with JDK 9.
So what i want is a small utility or a smart way to switch between JDK 8 and JDK 9 on demand basis.
For the time being, what i am doing is:
Open a terminal.
biz=data.frame(
year=query1$YEAR,
ProdNm=query1$PROD_NM,
Total = as.numeric(as.character(query1$TOTAL)),
Sold_that_day = query1$QTY,
Month = query1$MONTHNAME,
Weekand= query1$WEEKNAME,
AreaName=query1$AREA_NAME,
Manufacturer=query1$MFG,
stringsAsFactors = FALSE
)
# Total sales By year In 2017 #
totalsales="select year(RETAIL_STR_SALES_DETAIL.SALE_DATE) as YEAR,
monthname(RETAIL_STR_SALES_DETAIL.SALE_DATE) AS MONTHNAME
,round(sum(RETAIL_STR_SALES_DETAIL.total),2) as TOTAL
from retail_str_sales_detail where year(RETAIL_STR_SALES_DETAIL.SALE_DATE)='2017'
group by year(RETAIL_STR_SALES_DETAIL.SALE_DATE),
monthname(RETAIL_STR_SALES_DETAIL.SALE_DATE)";
totalsalesbyyear <- fetch(dbSendQuery(conn,totalsales), -1)
bizmonthly=data.frame(
MonthName=factor(totalsalesbyyear$MONTHNAME,levels = month.name),
Year=totalsalesbyyear$YEAR,
MonthTotal=as.numeric(as.character(totalsalesbyyear$TOTAL))
)
print(bizmonthly)
Set the JAVA_HOME temporarily to jdk 9
kv:micro-tab karan.verma$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
start the jshell
kv:Home karan.verma$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
close the terminal when done. That means, the global JAVA_HOME works now.
kv:Home karan.verma$ jshell
| Welcome to JShell -- Version 9.0.1
| For an introduction type: /help intro
So, my question is, Is there is any better approach to do it? Or this is the a good practice to do such kind of things? Please suggest.
答案 0 :(得分:0)
您可以编写脚本。重置环境并在路径中启动jshell。
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(fragLogin.this._main, gso);
mSignInGoogle0.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
if (account != null)
{
mPasswordView.setVisibility(View.GONE);
mPasswordView.setVisibility(View.GONE);
}
updateUI(account);
} catch (ApiException e) {
e.printStackTrace();
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
lib.ShowMessage(getContext(), getString(R.string.googleloginnotsuccessfull) + "\n" + getString(R.string.ErrorCode) + GoogleSignInStatusCodes.getStatusCodeString(e.getStatusCode()) + ":" + e.getStatusCode(), getString(R.string.Error));
updateUI(null);
}
}
答案 1 :(得分:0)
这是我解决问题的方法:
卸载JDK 9,安装jdk 8,然后安装jdk 9。
为版本8和9添加相应的JAVA_HOME路径。为其设置别名,并将Java 8设置为默认JDK。
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_9_HOME=$(/usr/libexec/java_home -v1.9)
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java9='export JAVA_HOME=$JAVA_9_HOME'
#default java8
export JAVA_HOME=$JAVA_8_HOME
现在只需使用别名设置Java 8或Java 9即可在版本之间进行切换,如下所示:
java8
java9