问题
Maximo 7.6.1.1:
Using Jython, I want to open a URL in a browser (in Windows 10).
I've found a Java example:
import java.awt.Desktop;
import java.net.URI;
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI("http://www.example.com"));
}
And I've attempted to convert it to Jython:
from java.awt import Desktop
from java.net import URI
desktop = Desktop.getDesktop()
uri = URI("http://google.com/#q=wonum1%2Cwonum2%2Cwonum3")
desktop.browse(uri)
While the Jython does compile successfully, it does not open the browser.
How can I open a URL in a browser using Jython?
回答1:
The short answer
"You can't." Or, more accurately, "It's probably not worth the effort / risk."
The long answer
From previous experience, using VB to write CGI (which I do NOT recommend), I would guess that putting the code from your question in an automation script might cause a browser session to get launched on the server, where your script was run. Things may have changed since those VB days, 20+ years ago, but I would still be tempted to check.
@Milton was on the right track, I think, but with Maximo it would actually be a little more complicated. This is because when he said, "You could have [the script] return a response", that response would be returned from the business logic layer on the server side to the UI layer on the server side which would then have to return it to the browser, which you would have had to "big C" customize Maximo to expect that response and know what to do with it.
The alternative
You could maybe return an error from your script, and have the message include a URL. Or use an Autoscript + Conditional UI + Launch in Context + Nonpersistent Attribute mix to expose a link for the user to click.
回答2:
As some have have indicated, automation scripts in Maximo are run on the server side. These scripts are setup based on certain types of launch points to activate when the script will run on the server side. In general the automation scripts can not really be used to manipulate the UI elements because these are controlled on the webclient layer.
What launch point type was used with the example Jython code above? It might work if it were an action type launch point associated with a push button in the UI. But I am unsure the context for how and when you are wanting this action to occur. But more than likely it still would not work because the Java code is still being run from the server side and not the client. Typically, you would have to create a custom Java class file extention for the application to add to the webclient layer. Though most organizations try to stay away from these type of true customizations because of the issues it can cause with future updates and upgrades to the base Maximo product.
Maximo has an out of the box functionality built in that allows a user to launch in context URLs. Here is an IBM link that has a pdf of an example of launching an address associated from a record in Maximo into Google Maps.
https://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=a9ba1efe-b731-4317-9724-a181d6155e3a#fullpageWidgetId=W5f281fe58c09_49c7_9fa4_e094f86b7e98&file=a6af8bfb-8b72-4b57-945c-786ab4d71b14
Also I am not sure exactly what the purpose is for the requirement. But I have also seen were if you were just trying to retrieve information from an external source you can actually display the information directly in the Maximo application if the external web application can be access through a webservice type interaction.
来源:https://stackoverflow.com/questions/58488528/jython-open-url-in-browser-without-importing-python-libraries