小编mab*_*aba的帖子

排除在IntellIJ中运行的测试

在IntelliJ IDEA Ultimate中排除某些测试是不是可以吗?我想在IntelliJ中运行单元测试但排除集成测试.我将集成测试命名为,*IT.java因此Maven故障安全插件可以从单元测试中单独运行它们.

java junit intellij-idea maven

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

CDI:beans.xml,我在哪里放你?

我使用Weld作为CDI实现.当我有空的beans.xml时,我试图组装实例化Weld容器的对象图的集成测试运行良好src/test/java/META-INF/beans.xml.这是一个简单的测试:

public class WeldIntegrationTest {
    @Test
    public void testInjector() {
        new Weld().initialize();
        // shouldn't throw exception
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我跑步时mvn clean install,我总是得到:Missing beans.xml file in META-INF!

我的根文件夹是"src"和"web",其中包含WEB-INF文件夹,但我也尝试使用默认的maven结构并将"web"重命名为"webapp"并将其移至src/main.我尝试了所有合理的位置:

 - src/main/java/META-INF/beans.xml
 - src/test/java/META-INF/beans.xml
 - web/WEB-INF/beans.xml
 - src/main/webapp/WEB-INF/beans.xml
 - src/main/webapp/META-INF/beans.xml
 - src/main/webapp/META-INF/(empty) and src/main/webapp/WEB-INF/beans.xml
Run Code Online (Sandbox Code Playgroud)

到目前为止没有任何作用:/

java java-ee maven cdi jboss-weld

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

我可以在maven pom.xml中使用属性文件进行flyway配置

<plugin>
    <groupId>com.googlecode.flyway</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <driver>com.mysql.jdbc.Driver</driver>
        <url>jdbc:mysql://127.0.0.1:3306/db_abc</url>
        <user>db_user</user>
        <sqlMigrationPrefix>V</sqlMigrationPrefix>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我不想在这里提到驱动程序,网址和用户.我已经有一个abc.propertysrc/main/resources.怎么在这里使用该文件?

pom.xml maven flyway

23
推荐指数
2
解决办法
3万
查看次数

从JNI操纵ByteBuffer

我需要将(直接)传递给ByteBuffer将从缓冲区读/写的本机函数.完成这些操作后,我想ByteBuffer使用常规函数访问Java代码; 特别是,limit()position()要体现缓冲器的当前状态.

由于JNI将使用GetDirectBufferAddress()直接访问底层缓冲区,我假设我应该在读完/写入后调用flip ()/ limit()/ position().但是,我一直无法做到这一点.例如,在我从C读取几个字节进入缓冲区并相应地设置其限制和位置后,我无法从Java查询这些字节; Java对缓冲区限制和位置的想法与我在C代码中所做的不一致.

任何人都可以向我指出一个有效的例子吗?提前致谢.

java java-native-interface bytebuffer

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

Java在实现具有较弱访问权限的接口方法时出错

当我编译这段代码时:

interface Rideable {
    String getGait();
}

public class Camel implements Rideable {
    int x = 2;

    public static void main(String[] args) {
        new Camel().go(8);
    }

    void go(int speed) {
        System.out.println((++speed * x++) 
        + this.getGait());
    }

    String getGait() {
        return " mph, lope";
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Camel.java:13: error: getGait() in Camel cannot implement getGait() in Rideable
String getGait() {
       ^
  attempting to assign weaker access privileges; was public
1 error
Run Code Online (Sandbox Code Playgroud)

如何在接口中声明的getGait方法被公开?

java interface

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

catch块在c ++本机库中不起作用

我正在用c ++编写一个java本机库,并在本机lib本身中使用异常处理,但是一旦抛出异常,库就会崩溃.这是我的简单测试程序,当我从Java测试中调用它时,它会在抛出异常时立即崩溃.catch块无法正常工作.我想念的任何想法.谢谢.

#include "Test.h"
#include <iostream>

JNIEXPORT void JNICALL Java_Test_helloWorld(JNIEnv *, jobject)
{
    std::cout<<"Hello World";
    try {
        throw 1;
    }
    catch(int )
    {
        std::cout<<" catch int block"<<std::endl;
    }
    catch(...)
    {
        std::cout<<" catch block"<<std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

编译和链接:

g++ -m64 -fPIC -fexceptions -c test.cpp
g++ -shared -m64 -Wl,-soname,libtest.so -Wl,-shared-libgcc test.o -o libtest.so

$ java  -d64 -Djava.library.path=/home/vkumar/projects/test -cp $CLASSPATH Test
terminate called after throwing an instance of 'int'
terminate called recursively
Hello World^CAbort (core dumped)
Run Code Online (Sandbox Code Playgroud)

c++ java java-native-interface native exception

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

Maven运行时范围和循环依赖

我有两个模块A和B.Actualy B是A的插件
.B在编译时依赖于A. 不依赖于B.在运行时我想将B添加到类路径中,所以在A的pom.xml中我添加了以下依赖项

pom.xml

    <dependency>
        <groupId>my_group</groupId>
        <artifactId>my_Plugin</artifactId>
        <version>${project.version}</version>
        <scope>runtime</scope>
    </dependency> 
Run Code Online (Sandbox Code Playgroud)

Maven进程因循环依赖性错误而失败

[ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='A'}' and 'Vertex{label='B'}' introduces to cycle in the graph B-->A-->B -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

[错误]

为什么运行时依赖会影响编译时

runtime cyclic maven

9
推荐指数
1
解决办法
3898
查看次数

通过jni将jint数组从c返回到java

我在java中创建了一个整数数组,并通过jni将数组传递给cpp程序我的代码是:

import java.util.*;

class SendArray {
  //Native method declaration
  native int[] loadFile(int[] name);
  //Load the library
  static {
    System.loadLibrary("nativelib");
  }

  public static void main(String args[]) {
    int arr[] = {1,2,3,4,5,6,7,8,9,10};
    //Create class instance
    SendArray mappedFile=new SendArray();
    //Call native method to load SendArray.java
    int[] buf = mappedFile.loadFile(arr);
    //Print contents of SendArray.java
    for(int i=0;i<buf.length;i++) {
      System.out.print(buf[i]);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在cpp程序中,我正在反转数组并将数组返回到java programee我的代码是::

#include <iostream>

using namespace std;

JNIEXPORT jintArray JNICALL Java_SendArray_loadFile
  (JNIEnv * env, jobject jobj, jintArray array) {
          cout<<"Orignal Array is:"<<endl; 
          int …
Run Code Online (Sandbox Code Playgroud)

java java-native-interface

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

在调整大小时,多线程环境中的Hashmap

我正在学习一个教程,它基本上解释了在多线程环境中调整Hashmap大小时发生的竞争条件的原因:

在Java中,如果两个线程同时发现现在HashMap需要调整大小并且它们都尝试调整大小.在Java中的HashMap的调整过程中,存储在链表斗元素迁移到新的水桶中得到逆转,从而因为Java的HashMap不附加在尾部的新元素,而不是它在头部添加新元素避免尾部穿越.如果发生竞争条件,那么最终会出现无限循环

阅读本文后我有两个问题:

  1. 为什么每个存储桶的链表按顺序颠倒?
  2. 我可以看到可能存在竞争条件,但无法看到无限循环是如何产生的?是因为一个线程可能会将元素头部追尾,而另一个线程以相反的顺序执行它?

请帮我澄清一下,非常感谢!

java hashmap

8
推荐指数
2
解决办法
7556
查看次数

不幸的Java异常:java.lang.NoSuchMethodError

我写了一个应用程序,它工作了3年,但是!今天,当他们尝试运行此应用程序时,出现了意外的异常:

INFO   | jvm 1    | 2013/04/17 10:02:40 | Exception in thread "Thread-1" java.lang.NoSuchMethodError: java.sql.Connection.isValid(I)Z
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.MySQLConnectionPatch.SearchInCache(MySQLConnectionPatch.java:103)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.MySQLConnectionPatch.getConnection(MySQLConnectionPatch.java:79)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.SQLManager.establishSqlConnection(SQLManager.java:62)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.SQLManager.establishSqlConnection(SQLManager.java:30)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.tasks.classes.sql.executeQuery.execute(executeQuery.java:49)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.TTask.run(TTask.java:86)
INFO   | jvm 1    | …
Run Code Online (Sandbox Code Playgroud)

java exception nosuchmethoderror

7
推荐指数
2
解决办法
1920
查看次数