小编Ste*_* S.的帖子

无法获取状态更改锁定

我们的产品使用最新的生产就绪型SWT,3.7.2.既然当时没有人知道下一个Java版本会被调用(以及他们怎么会知道8之后是8,这就像高等数学一样),我们被迫将org.eclipse.osgi3.7.2 交换到3.10.0,这样我们现在可以支持Java 8.虽然这可能不是最好的想法,但理论上它应该可行.

当然,作为Eclipse Luna的主要搞砸,当我们启动应用程序时会出现这个"错误"(大约50%的时间,我猜):

org.osgi.framework.BundleException: Unable to acquire the state change lock for the module: osgi.identity; osgi.identity="org.eclipse.osgi"; type="osgi.bundle"; version:Version="3.10.0.v20140606-1445"; singleton:="true" [id=0] STARTED [STARTED] invalid
at org.eclipse.osgi.container.Module.lockStateChange(Module.java:329)
at org.eclipse.osgi.container.SystemModule.init(SystemModule.java:44)
at org.eclipse.osgi.container.SystemModule.start(SystemModule.java:170)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:393)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:412)
at org.eclipse.equinox.internal.simpleconfigurator.ConfigApplier.startBundles(ConfigApplier.java:307)
at org.eclipse.equinox.internal.simpleconfigurator.ConfigApplier.install(ConfigApplier.java:108)
at org.eclipse.equinox.internal.simpleconfigurator.SimpleConfiguratorImpl.applyConfiguration(SimpleConfiguratorImpl.java:129)
at org.eclipse.equinox.internal.simpleconfigurator.SimpleConfiguratorImpl.applyConfiguration(SimpleConfiguratorImpl.java:143)
at org.eclipse.equinox.internal.simpleconfigurator.Activator.start(Activator.java:48)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)
at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721)
at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:936)
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:319)
at org.eclipse.osgi.container.Module.doStart(Module.java:571)
at org.eclipse.osgi.container.Module.start(Module.java:439)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
at org.eclipse.osgi.container.SystemModule.startWorker(SystemModule.java:242)
at org.eclipse.osgi.container.Module.doStart(Module.java:571)
at org.eclipse.osgi.container.Module.start(Module.java:439) …
Run Code Online (Sandbox Code Playgroud)

java osgi eclipse-luna

17
推荐指数
4
解决办法
2万
查看次数

缺少神器"sun.jdk:jconsole:jar:jdk"

将Arquillian添加到Maven构建时,我在Eclipse中获得了上述异常:

缺少神器sun.jdk:jconsole:jar:jdk

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>1.1.7.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.extension</groupId>
        <artifactId>arquillian-persistence-dbunit</artifactId>
        <version>1.0.0.Alpha7</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

(消息不是问题,但Eclipse因为它而拒绝编译项目.不过Maven工作.)

当然,我做的第一件事就是尝试将其从Maven依赖项中排除(wildfly-arquillian-container-managed依赖树声明依赖性来自哪里):

    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-arquillian-container-managed</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>jconsole</artifactId>
                <groupId>sun.jdk</groupId>
            </exclusion>
        </exclusions>
    </dependency> 
Run Code Online (Sandbox Code Playgroud)

没有变化.我尝试用Eclipse启动Eclipse -vm C:\Program Files\Java\jdk1.8.0_60\bin.并尝试在"首选项 - >已安装的JRE"中编辑JDK,以在工具目录中包含JAR.但没有任何作用.

我能做什么?

eclipse maven jboss-arquillian wildfly

10
推荐指数
3
解决办法
1万
查看次数

覆盖方法的弃用

我在Eclipse IDE中发现了一些奇怪的东西.假设我有以下课程:

public class Super {
    @Deprecated
    public void doNotUseThisMethod() {
        // do magic
    }
}

public class Sub extends Super{
    @Override
    public void doNotUseThisMethod() {
        // why is this not deprecated?
    }
}
Run Code Online (Sandbox Code Playgroud)

当然,覆盖已弃用的方法应该会产生警告(因为不使用它的原因相同).仍然在Eclipse Luna和Mars的全新工作区中,上面的代码根本不会产生警告.我也找不到任何方法来启用它.

我发现这个接口的错误(我知道如果Super是一个接口,应该没有警告),这意味着曾经有一个警告.

所以发生了什么事?是否有任何理由覆盖已弃用的方法不应导致警告?我可以做些什么来重新启用此功能吗?

java eclipse deprecated deprecation-warning

8
推荐指数
1
解决办法
2173
查看次数

触发Maven远程释放

我想以编程方式从Java程序启动Maven版本.该网页显示了一般如何完成.这就是我做的:

    final URL url = new URL("http://jenkins/job/MyProject/m2release/submit");

    final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestMethod("POST"); 
    urlConnection.setDoOutput(true);

    final String userpass = "User:Password";
    final String authentication = "Basic " + DatatypeConverter.printBase64Binary(userpass.getBytes());
    urlConnection.setRequestProperty("Authorization", authentication);

    try (final OutputStream os = urlConnection.getOutputStream();
            final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));) {
        writer.write("releaseVersion=1.2.3&");
        writer.write("developmentVersion=1.2.4-SNAPSHOT&");
        // writer.write("isDryRun=on&"); // uncomment for dry run
        writer.write("scmUsername=User&");
        writer.write("scmPassword=Password&");
        writer.write("scmCommentPrefix=[test]&");
        writer.write("json={\"releaseVersion\":\"1.2.3\",\"developmentVersion\":\"1.2.4-SNAPSHOT\",\"isDryRun\":false}&");
        writer.write("Submit=Schedule Maven Release Build");

        writer.flush();
    }

    urlConnection.connect();

    try (BufferedReader reader = new BufferedReader(
            new InputStreamReader(urlConnection.getInputStream(), "UTF-8"))) {
        for (String line; …
Run Code Online (Sandbox Code Playgroud)

jenkins

8
推荐指数
1
解决办法
784
查看次数

Eclipse 不断冻结

我听说过“Eclipse 默哀一分钟”的谣言,但我不知道它有多糟糕。

我已经安装了全新的 Eclipse(来自 ZIP 包)并且只安装了 JBoss 工具。现在,Eclipse 在接近每个快捷键时都会冻结,但至少每 30 秒冻结一次。Ctrl+C?一分钟冻结。不复制。Ctrl+D?冻结一分钟。另外,不删除任何行。单击进入编辑器?冻结一分钟。它还会带走所有东西,例如,当 Eclipse 冻结时,我的浏览器将无法工作。

这样工作是不可能的。完全没有。我的同事刚刚回到 Eclipse 2018-09,但我需要 Java11,所以我不能。

我找不到此问题的任何错误(Eclipse 冻结有很多错误,但 2018-12 中不应仍然存在)。

还有其他人经历过类似的事情吗?这是我们整个办公室的问题,所以不仅仅是一台有故障的计算机。这是否与 Eclipse 将其配置文件分散在硬盘驱动器上的方式有关?也许它无法读取 2018-09 配置文件或其他什么?

eclipse

8
推荐指数
1
解决办法
1万
查看次数

WorkbenchPage.busyShowView中的NullPointerException

我有一个简单的视图,通常在我的Eclipse插件(4.5.2)中注册,当我使用插件启动Eclipse实例时,它可以正常工作.它仍然适用于相应的测试用例,它具有以下方法:

@Before
public void setUp() throws Exception {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IViewReference viewReference : activePage.getViewReferences()) {
        activePage.hideView(viewReference);
    }
    activePage.showView("org.acme.MyView");
}
Run Code Online (Sandbox Code Playgroud)

然而,当我使用Tycho(0.22,0.24或0.25)运行相同的测试时,我得到以下异常:

java.lang.NullPointerException: null
    at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1271)
    at org.eclipse.ui.internal.WorkbenchPage$12.run(WorkbenchPage.java:4238)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:4234)
    at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:4214)
    at org.acme.MyViewTest.setUp(MyViewTest.java:39)
Run Code Online (Sandbox Code Playgroud)

第谷代码很简单:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-surefire-plugin</artifactId>
    <configuration>
        <providerHint>junit4</providerHint>
        <useUIHarness>true</useUIHarness>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我发现了这个bug以及更多,但我没有发现任何解释为什么它只会在第谷失败.我找不到任何关于如何解决这个问题.

那我做错了什么?我如何解决它?

eclipse-plugin tycho e4

6
推荐指数
1
解决办法
148
查看次数

将Serializable引入现有代码

我认为这应该是一个非常普遍的案例,但我找不到任何最佳做法.假设我有以下课程:

public class Equation {

    private Operator operator;
    private Object leftValue;
    private Object rightValue;

    // getters and setters
}

public enum Operator  {...}
Run Code Online (Sandbox Code Playgroud)

这堂课已经和我们一起使用了好几年了,而且使用得很好.现在我需要使它可序列化.我怎么做?

只需添加 implements Serializable

在这种情况下,Equation只有值有效,该类才有效Serializable.方程式只对数字(可能是日期和字符串?)真正起作用.但价值观可能是任何一种Object,所以必须有更好的方法.

创造价值 Serializable

public class Equation implements Serializable{

    private Operator operator;
    private Serializable leftValue;
    private Serializable rightValue;

    // getters and setters 
}
Run Code Online (Sandbox Code Playgroud)

这在任何情况下都有效,但这些更改是API中断.无论我做什么,我都需要使用类更改所有代码,这可能导致更多的API中断.对于可能需要很长时间的大型软件系统.

制作价值观Serializable,让getter和setter保持原样

public void setLeftValue(Object leftValue) {
    if (!(leftValue instanceof Serializable)) 
        throw new IllegalArgumentException("Value must be Serializable!");
    this.leftValue = leftValue;
}
Run Code Online (Sandbox Code Playgroud)

此代码不会破坏现有API,但会更改代码的行为方式.然而,如果我认为所有的价值观都是如此Serializable …

java

6
推荐指数
1
解决办法
130
查看次数

在Pom中将generateBackupPoms设置为False

我们所有的构建都在发布时在命令行中添加了参数“ -DgenerateBackupPoms = false”,我认为这是一种愚蠢的行为,我想将其添加到共享的父pom.xml中。但是我不知道是哪个插件生成了备用poms。

我搜索了Maven Release Plugin,但是没有运气。

然后我尝试了“ versions-maven-plugin”(至少具有参数),但是将其更改为false并没有帮助:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>versions-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <generateBackupPoms>false</generateBackupPoms>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

备份poms仍会生成。那么如何关闭它们呢?

maven

5
推荐指数
1
解决办法
680
查看次数

使用祖父窗口的默认方法

我完全迷失了为什么那不起作用:

interface Test {

    default void doMagic() {
        System.out.println("Abracadabra");
    }
}

class TestImpl implements Test {

}

class SpecialTestImpl extends TestImpl {

    public void doMagic() {
        Test.super.doMagic(); // Error: No enclosing instance of the type Test is accessible in scope
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一些奇怪的Eclipse错误消息(它也无法应对Lamdas,所以也许Mars还没有完全准备好Java 8)?

我可以通过直接让SpecialTestImpl工具Test(它产生警告,因为它是不必要的)或覆盖方法来解决它(由于TestImpl相同的原因产生警告).

那么为什么我不能调用超级方法呢?

我的猜测是因为如果我能够Test.super.doMagic()直接调用,实现该方法TestImpl会破坏API,SpecialTestImpl即使它不应该.但是如果我让SpecialTestImpl实现Test并以这种方式调用默认方法也是如此.

java eclipse java-8

5
推荐指数
1
解决办法
228
查看次数

Lambda在Websocket会话中不起作用

我刚遇到一个奇怪的小问题:

javax.websocket.Session session = //...
// this works
newSession.addMessageHandler(new MessageHandler.Whole<String>() {

    @Override
    public void onMessage(String message) {
        MyWebSocket.this.onMessage(message);
    }
});
// these don't work
newSession.addMessageHandler((MessageHandler.Whole<String>) MyWebSocket.this::onMessage);
newSession.addMessageHandler((MessageHandler.Whole<String>) message -> MyWebSocket.this.onMessage(message));


void onMessage(String message) {
    System.out.println(message);
}
Run Code Online (Sandbox Code Playgroud)

有人知道为什么lambda表达式在这个实例中不起作用吗?没有编译错误,没有异常,没有任何东西.没有调用方法''onMessage''.

我使用Java 1.8.0_65和Tyrus参考实现1.9.

java websocket tyrus

5
推荐指数
1
解决办法
421
查看次数