我有一个GWT应用程序(FooGwtApp)和一个库模块(FooLib),用作FooGwtApp中的依赖项。 FooLib的包装结构如下:
packageFoo.ImportantClass
packageFoo.UnimportantClass
packageBar.OtherClass
我希望GWT编译器将ImportantClass(并且只有ImportantClass)编译为JS。无法将ImportantClass移至另一个程序包。
我在packageFoo中创建了具有以下内容的ImportantClass.gwt.xml:
<module>
<inherits name="com.google.gwt.user.User"/>
<source path="" includes="**/ImportantClass*"/>
</module>
接下来,我在FooGwtApp.gwt.xml中放置了对ImportantClass模块定义的继承引用(这似乎起作用:IDE可以识别它,并且能够解析对ImportantClass.gwt.xml的引用)。
现在,如果我将对ImportantClass的引用放入FooGwtApp的客户端代码中,则GWT编译器将失败,因为它在源路径上未找到ImportantClass:
packageFoo.ImportantClass类型没有源代码;您忘了继承必需的模块吗?
我可能搞砸了ImportantClass.gwt.xml中源路径/ include属性中的某些东西-用path =“”将当前程序包定义为根程序包不是有效的符号,或者includes属性出了点问题。或两者。还是都不是。
您能给我一个关于哪里出错的线索吗?
答案 0 :(得分:0)
GWT模块文件中的源路径是相对于模块文件本身的。因此,如果您在packageFoo中创建了ImportantClass.gwt.xml,则需要这样做:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import mplcursors
import numpy as np
# expects series, annotation, and the annotation data to be shown on click
def stimeline(timeseries, annotation, onclick):
neg = np.random.randint(low=-500, high=0, size=len(timeseries))
pos = np.random.randint(low=0, high=500, size=len(timeseries))
i = 0
d = []
while i < len(timeseries):
if i < len(timeseries):
d.append(pos[i])
i += 1
if i < len(timeseries):
d.append(neg[i])
i += 1
(fig, ax) = plt.subplots(figsize=(8.8, 4), constrained_layout=True)
ax.stem(timeseries, d, basefmt=' ')
ax.set(title='Timeline')
ax.set_ylim(-545, 545)
levels = np.tile(d, int(np.ceil(len(timeseries)
/ 6)))[:len(timeseries)]
(markerline, stemline, baseline) = ax.stem(timeseries, levels,
linefmt='C3-', basefmt='k-')
plt.setp(markerline, mec='k', mfc='w', zorder=3)
vert = np.array(['top', 'bottom'])[(levels > 0).astype(int)]
for (d, l, r, va) in zip(timeseries, levels, annotation, vert):
ax.annotate(
r,
xy=(d, l),
xytext=(-3, np.sign(l) * 3),
textcoords='offset points',
va=va,
ha='right',
)
ax.get_yaxis().set_visible(False)
for spine in ['left', 'top', 'right']:
ax.spines[spine].set_visible(False)
mplcursors.cursor(ax).connect('add', lambda sel: \
sel.annotation.set_text(onclick[sel.target.index]))
ax.margins(y=0.1)
plt.show()
答案 1 :(得分:0)
事实证明,这个问题实际上不在ImportantClass.gwt.xml中,而在其他与Maven相关的东西中。即:
ImportantClass.gwt.xml应该放在src / main / 资源 / packageFoo下,而不是src / main / java / packageFoo下,否则它将不会不能打包到二进制jar中。
GWT编译器从Java 源编译为Javascript源。这意味着我们不仅需要FooLib.jar中的ImportantClass.class,还需要其源代码。最好的解决方案似乎是在FooLib的pom.xml中使用maven-source-plugin,并使用源分类器将FooLib依赖项导入FooGwtApp。
关于后一个主题,请参见以下SO答案:
Maven: Distribute source code with with jar-with-dependencies
How to properly include Java sources in Maven?
解决上述问题后,问题中存在的源路径声明起作用。
主持人:如果此问题和/或答案不符合SO的质量标准,请向我发送消息,然后我将其删除或以其他方式修复。 (对我来说有点尴尬,但是我不确定如何最好地解决它。)