我试图通过嵌入jetty开发Web服务器.所以对于jetty 7.3一切正常.昨天我将jetty库更新到最新版本8.0.3,现在我通过创建一个ServletContextHandler得到了一个Exception.
线程"main"中的异常java.lang.NoClassDefFoundError:org.eclipse.jetty.servlet.ServletContextHandler中的javax/servlet/FilterRegistration.(ServletContextHandler.java:126)org.eclipse.jetty.servlet.ServletContextHandler.(ServletContextHandler.java :106)在org.gemsjax.server.GemsJaxServer.main(GemsJaxServer.java:38)的org.eclipse.jetty.servlet.ServletContextHandler.(ServletContextHandler.java:94)
所以我做的是:
public static void main(String[] args) {
Server server = new Server(8080);
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setContextPath("/servlets");
servletContext.addServlet(new ServletHolder( new CollaborationWebSocketServlet()),"/collaboration");
// The ResourceHandler to handle static web content
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{ "index.html" });
resourceHandler.setResourceBase("./war/");
ContextHandler resourceContext = new ContextHandler();
resourceContext.setContextPath("/static");
resourceContext.setHandler(resourceHandler);
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(resourceContext);
handlers.addHandler(servletContext);
server.setHandler(handlers);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
抛出异常的行是:
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
Run Code Online (Sandbox Code Playgroud)
我使用ubuntu 11.04: …
是否可以检查用户是否已点击带有target ="_ blank"的html链接.
我想要做的是在我的应用程序中在WebView中显示htlm,但在android默认浏览器中启动"外部"链接."外部"链接对我来说是一个target ="_ blank"的链接.所有其他链接应在webview中处理.
例如:用户在我的WebView中点击这样的链接:
<a href="http://www.google.com" target="_blank">new window</a>
Run Code Online (Sandbox Code Playgroud)
然后我想在Android浏览器中打开给定的URL.
我用shouldOverrideUrlLoading()尝试了它,但此时我无法确定目标是"_blank"还是普通链接(没有目标).
我也试过setSupportMultipleWindows(true); 与onCreateWindow()结合使用,但在此回调中我无法获取url.
我无法更改显示的HTML,因此我无法使用带有addJavascriptInterface()的JavaScript Bridge
我还可以做些什么?还有其他想法吗?
我想用自己的xml属性创建自定义视图.我想指定一个在我的自定义xml视图中膨胀的标题布局,如下所示:
<com.example.MyCustomWidget
android:layout_width="match_parent"
android:layout_height="match_parent"
app:headerLayout="@layout/my_header"
/>
Run Code Online (Sandbox Code Playgroud)
这是可能的,如何从中获取布局资源TypedArray?
所以最后我想做这样的事情:
class MyCustomWidget extends FrameLayout {
public ProfileTabLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProfileTabLayout);
int headerLayout = a.getLayout(R.styleable.MyCustomView_headerLayout, 0); // There is no such method
a.recycle();
LayoutInflater.from(context)
.inflate(headerLayout, this, true);
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomWidget">
<attr name="headerLayout" format="reference" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud) 不幸的是我必须支持Android 2.3,但我想使用具有min-sdk 14(Android 4.0)的第三方ui小部件.
有没有办法在min-sdk 14中包含依赖项?
在代码中,我将检查Build.SDK_INT以确定是否将ui小部件与min SDK 14或后备UI小部件一起使用.
我写了一个注释处理器。用户可以传递一个选项作为处理器的参数。我也可以在我的注释处理器中读取这个参数。到目前为止一切顺利,一切都按预期进行!
但是,我从编译器收到警告,传递给注释处理器的选项尚未被任何注释处理器识别:
警告:以下选项未被任何处理器识别:'[fragmentArgsLib]'
实际上,我的处理器已成功识别并读取此选项:
@Override public boolean process(Set<? extends TypeElement> type, RoundEnvironment env) {
String fragementArgsLib = processingEnv.getOptions().get("fragmentArgsLib");
...
}
Run Code Online (Sandbox Code Playgroud)
我想我必须手动说我已经使用这个选项来使这个编译器警告消失。你们中有人知道怎么做吗?
我编写了一个AnnotationProcessor扫描代码中某个注释并从中生成 Java 类的程序。它基本上做了这样的事情:
private Multimap<String, Element> elements;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Factory.class)) {
elements.put(annotatedElement.getSimpleName());
}
generateCode(elements);
}
Run Code Online (Sandbox Code Playgroud)
以防万一:
generateCode()将迭代elements,这是一个多重映射,并为每个键创建一个类(键+后缀是我想要生成的文件的名称),并使用根据元素列表的信息创建的代码(与 key 关联的某个 key 的 multimap 的值。
显然我会调用generateCode()每一轮注释处理。因此,我会收到一个编译错误,表明在上一轮中已经生成了同名的文件。
处理这个问题的正确方法是什么?我认为收集所有注释并仅在最后一轮生成类是个好主意,如下所示:
private Multimap<String, Element> elements;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Factory.class)) {
elements.put(annotatedElement.getSimpleName());
}
if (roundEnv.processingOver()){
generateCode(elements);
}
}
Run Code Online (Sandbox Code Playgroud)
这解决了多次生成相同文件的问题,但现在我收到以下警告:
警告:java:上一轮创建的类型为[生成的java文件的路径]的文件将不会受到注释处理。
javadoc 指出您不应该在上一轮中生成代码。我应该什么时候生成我的文件?
此外,如果我单击重建项目,我还会在 IntelliJ 14 中收到此警告:警告:输出路径 [生成的 …
我有一个像这样的java界面
public interface MyInterface<T> {
public <V extends T> V get(String key, Bundle bundle);
}
Run Code Online (Sandbox Code Playgroud)
请注意方法的<V extends T>类型参数.
然后我上课了 MyFoo implements MyInterface
class MyFoo implements MyInterface<Object> { // Object because can be any type
@Override public <V> V get(String key, Bundle bundle) {
return new Other();
}
}
Run Code Online (Sandbox Code Playgroud)
所以,当我现在有这样一个类:
class Bar {
public Other other;
public Other setOther(Other other);
}
Run Code Online (Sandbox Code Playgroud)
然后我想在一个实例中MyFoo设置:OtherBar
MyFoo foo = new MyFoo();
Bar bar = new Bar();
bar.other = foo.get(); …Run Code Online (Sandbox Code Playgroud) 由于android gradle插件默认启用了增量构建,因此注释处理会中断,因为只有那些自上次增量构建以来已更改的类才会从注释处理器中考虑.
因此对于java源代码,我们通常使用aptgrald插件来运行注释处理.但是,如果apt在同一个项目中使用,android的gradle插件会自动禁用gradle的增量构建功能:https:
//github.com/google/dagger/issues/298
现在我正在开发一个kotlin项目,我面临同样的增量构建问题kapt.因此,解决方案apt就是禁用增量构建.文件说:
android {
compileOptions.incremental = false
...
}
Run Code Online (Sandbox Code Playgroud)
但是,这对我不起作用.有人知道如何禁用增量构建吗?
是否可以在基于 maven 的项目中运行 kapt(kotlin 注释处理)?
如果是,我如何将 kapt 集成到 Maven 构建系统中?
这可能是一个愚蠢的问题,但是如何在RxJava 2.0中Disposable订阅一个SubjectObservable?
例如:
observable.subscribeWith( behaviorSubject)
Run Code Online (Sandbox Code Playgroud)
不归还Disposable?如何取消此类订阅?
或者另一个例子CompositeDisposable:
compositeDisposable.add( observable.subscribeWith( behaviorSubject) ) )
Run Code Online (Sandbox Code Playgroud)
这不会编译因为subscribeWith( behaviorSubject )不返回Disposable.
如何取消订阅/处理/取消主题?