2 apps in the same JRE, are getting different resu

2019-08-07 13:55发布

问题:

I have a Maven Project that uses java.awt.Desktop. I'm using it for Google Authentication, so I need some way to open a browser dialog for Google Login, and user confirmation.

I'm exporting that library in a .jar file, that I intend to include it in lots of Liferay Portlets, in WEB-INF/lib

If I test the standalone project, running from the Liferay's Tomcat jre, Everything works fine, and Desktop.isDesktopSupported() returns true.

When a portlet, deployed on the Same Tomcat, calls the same library function, the Desktop.isDesktopSupported() returns false.

Since in both cases, I'm using the Same Java Environment, why am I getting a different behavior?

Also, if you know an alternative way to open a browser window instead of using Desktop.browse, it would be nice to share.

回答1:

Still not sure why it's not working in Servlet/PortletContext.

A workaround is opening the os browser with Java.lang.Runtime, as demonstated here