我在jar文件中有一个API但是如何在JavaScript中使用jar中的类?当我尝试导入它们时,
conf = Packages.abcapi.Config;
var cfg = new conf.Config();
Run Code Online (Sandbox Code Playgroud)
它不起作用.这不会在浏览器或互联网上使用.
更新:
我正在使用Java ScriptEngine将API扩展到所有JSR-223脚本语言.在Java应用程序内部,我读取了一个JavaScript文件,然后使用ScriptEngine执行该文件.我需要JavaScript文件来使用API中的类,它们位于一个jar文件中.我在运行ScriptEngine时尝试在类路径中设置jar,但它仍然没有使用上面的代码找到类.这在Jython中运行良好,因为在类路径中设置jar后,在Jython中使用jar文件中的类没有问题.
以下代码,
String string = "<xml attributes>some xml code</xml>"
+ "<xml attributes>some xml code</xml>"
+ "<xml attributes>some xml code</xml>"
+ "<xml attributes>some xml code</xml>";
String[] stringArray = string.split("<xml");
for ( String i : stringArray) {
System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)
打印
attributes>some xml code</xml>
attributes>some xml code</xml>
attributes>some xml code</xml>
attributes>some xml code</xml>
Run Code Online (Sandbox Code Playgroud)
但我想保留每个数组索引中的< xml字,以便输出,
<xml attributes>some xml code</xml>
<xml attributes>some xml code</xml>
<xml attributes>some xml code</xml>
<xml attributes>some xml code</xml>
Run Code Online (Sandbox Code Playgroud) 我有一个 Ant 项目,它可以自行构建得很好。我现在正尝试将其包装在 Maven 构建中,该构建将使用maven-antrun-plugin
. 当我这样做时,构建失败并收到此错误,
[ERROR] C:\Users\bobby\workspace\libraries\build-targets\common-targets.xml:170: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "C:\Java\jdk1.8.0_65\jre"
Run Code Online (Sandbox Code Playgroud)
有很多关于此错误的 SOF 帖子,但我觉得我的帖子是独一无二的,因为它仅在我将 Ant 构建包装在 Maven 中时才会发生,即,当我只是说 时,我不会在同一个项目上收到此错误$ ant build
。
这是我的pom.xml文件的一部分
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<ant antfile="build.xml" target="build" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions> …
Run Code Online (Sandbox Code Playgroud) 除周六和周日外,是否可以创建每天运行的Airflow DAG?这似乎不可能,因为你只有一个start_date和一个schedule_interval.
我正在设置一个工作流程,每天早上处理一批文件.这些文件不会在周末出现,只在周一到周五.我可以简单地使用24小时的超时设置,这实际上会使星期六和星期日超时,因为该文件永远不会出现在那些日子,但这会使DAG在这两天失败,这将是非常愉快的.
我有一个使用Airflow版本1.9的Airflow环境,该环境在Amazon EC2实例上运行.我需要升级到Airflow的最新版本1.10.我可以选择从1.9版升级或在新服务器上新安装1.10.气流版本1.10未在Pip上列出,所以我通过此命令从Git安装它,
pip-3.6 install git+git://github.com/apache/incubator-airflow.git@v1-10-stable
Run Code Online (Sandbox Code Playgroud)
此命令成功安装Airflow版本1.10.您可以通过运行命令airflow version
并查看输出来查看
____________ _____________
____ |__( )_________ __/__ /________ __
____ /| |_ /__ ___/_ /_ __ /_ __ \_ | /| / /
___ ___ | / _ / _ __/ _ / / /_/ /_ |/ |/ /
_/_/ |_/_/ /_/ /_/ /_/ \____/____/|__/
v1.10.0
Run Code Online (Sandbox Code Playgroud)
当我尝试启动Airflow调度程序时,airflow scheduler
我得到以下异常,
ModuleNotFoundError: No module named 'MySQLdb'
[2018-08-14 14:03:16,195] {celery_executor.py:112} ERROR - Error syncing the celery executor, ignoring it:
[2018-08-14 14:03:16,195] {celery_executor.py:113} ERROR - …
Run Code Online (Sandbox Code Playgroud) 我要考虑我以前在Stackoverflow上发布的内容,因为它现已在PyPi上发布,所以我终于从Airflow 1.9版升级到1.10版。使用此处的发布指南,我可以使用Airflow 1.10。现在,我检查了它们到1.10的udpates,以查看它们如何解决在 AWS EC2-Instance上运行时在Airflow 1.9版中发现的错误。我发现他们用对这个新的Airflow类的函数get_hostname
https://github.com/apache/incubator-airflow/blob/master/airflow/utils/net.py的调用替换了获得服务器IP地址的所有函数。现在,在这个小函数中,您会看到以下注释:
使用可从配置中调用的主机名或使用socket.getfqdn作为后备来获取主机名。
因此,在该注释之后,您会看到代码,
callable_path = conf.get('core', 'hostname_callable')
Run Code Online (Sandbox Code Playgroud)
这在airflow.cfg
下面的部分告诉我们,[core]
有一个新的键值字段hostname_callable
,该字段现在使我们可以设置如何获取服务器IP地址。因此,他们对在Airflow 1.9版中出现的错误的修复是让我们选择是否需要更改IP地址时如何获取IP地址。在此部分下的https://github.com/apache/incubator-airflow/blob/master/airflow/config_templates/default_airflow.cfg中,可以看到此新配置字段的默认值[core]
。您可以看到他们将其设置为
[core]
# Hostname by providing a path to a callable, which will resolve the hostname
hostname_callable = socket:getfqdn
Run Code Online (Sandbox Code Playgroud)
因此,他们使用的函数调用socket:getfqdn
会导致在AWS EC2-Instance上运行时发生错误。我需要使用它socket.gethostbyname(socket.gethostname())
(再次在我以前的文章中对此进行了详细介绍)
所以我的问题是,为了socket.gethostbyname(socket.gethostname())
使用冒号的配置样式,我需要使用什么语法:
?例如,函数调用socket.getfqdn()
被写入配置文件中socket:getfqdn
。因此,我看不到如何通过嵌套调用编写该语法。我会写类似的东西socket:gethostbyname(socket.gethostname())
吗?