我有一个maven项目,我想jacoco用于代码覆盖.这是我的pom的相关部分
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>pre-my-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-my-test</id>
<phase>post-my-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
所以我能够很好地运行我的测试,并且还可以很好地构建项目.然后我跑了
mvn clean verify org.jacoco:jacoco-maven-plugin:prepare-agent
Run Code Online (Sandbox Code Playgroud)
我不断收到错误
ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:
report (post-my-test) on project my-project:
An error has occurred in JaCoCo Test report generation.
Error while creating report:
Error while analyzing class /path/tp/my/project/target/classes/META-INF/
bundled-dependencies/some-third-party-1-jar-with-dependencies.jar@org/slf4j/event/
EventConstants.class. Can't add different class with same name:
org/slf4j/event/EventConstants -> [Help …Run Code Online (Sandbox Code Playgroud) 此方法用于将数组拆分为块引用。我想使这种方法通用。
问题是,我不能像这样初始化数组。
T[][] arrays = new T[chunks][];
Run Code Online (Sandbox Code Playgroud)
完整的方法
public <T> T[][] splitArray(T[] arrayToSplit, int chunkSize) {
if (chunkSize <= 0) {
return null;
}
int rest = arrayToSplit.length % chunkSize;
int chunks = arrayToSplit.length / chunkSize + (rest > 0 ? 1 : 0);
T[][] arrays = new T[chunks][];
for (int i = 0; i < (rest > 0 ? chunks - 1 : chunks); i++) {
arrays[i] = Arrays.copyOfRange(arrayToSplit, i * chunkSize, i * chunkSize + …Run Code Online (Sandbox Code Playgroud) 我在路径上部署了一个Web应用程序
/var/lib/tomcat6/webapps/abc/</code>
Run Code Online (Sandbox Code Playgroud)
在server.xml路径上/etc/tomcat/server.xml我添加了以下行.
<Context docBase="/var/lib/tomcat6/webapps/abc/" path="/" reloadable="true"> <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="10000" name="jdbc/abcDB" password="abc" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/abc" username="abc"/> </Context>
在主机标签内.
当我重新启动tomcat并且http://localhost:8080/什么都没有出现但是当我进入http://localhost:8080/abc主页时显示这意味着上面的输入server.xml没有生效.
我究竟做错了什么 ??
Java中有四种类型的引用:强,弱,弱和幻像.请详细说明Java在何处以及如何使用幻像引用.
编辑:
我确实读过javaDoc,就像下面发布的assylias一样.该部分说,如果一个物体已经完成并且有一些幻象参考指向它,那么这个物体就是幻像可重复的.我完全得到了这个说法.
幻影有什么用?我们在哪些情况下使用它?
我得到了异常,org.hibernate.HibernateException: Errors in named queries: ElaborazionePagamentiMaggioriOneri.estrai但命名查询对我来说是正确的.我也明白了
org.hibernate.hql.ast.QuerySyntaxException: ElaborazionePagamentiMaggioriOneri is not mapped [FROM ElaborazionePagamentiMaggioriOneri e WHERE e.dataInizioLancio IS NULL AND e.dataFineLancio IS NULL AND e.distinta IS NULL]
Run Code Online (Sandbox Code Playgroud)
我的实体如下:
@Entity(name="ELABORAZIONE_PAGAMENTI")
@Table(name="ELABORAZIONE_PAGAMENTI")
@NamedQuery(name="ElaborazionePagamentiMaggioriOneri.estrai",
query="FROM ElaborazionePagamentiMaggioriOneri e WHERE e.dataInizioLancio IS NULL AND e.dataFineLancio IS NULL AND e.distinta IS NULL")
public class ElaborazionePagamentiMaggioriOneri {
@Id
@GeneratedValue
@Column(name="ID_ELABORAZIONE")
private long idElaborazione;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_INTERVALLO")
private Intervallo intervallo;
@Column(name="IMPORTO_MINIMO")
private BigDecimal importoMinimo;
@Column(name="IMPORTO_MASSIMO")
private BigDecimal importoMassimo;
@Column(name="LIMITE_DISPOSIZIONI")
private Long limiteDisposizioni;
@Column(name="DATA_INIZIO_LANCIO")
private Calendar dataInizioLancio;
@Column(name="DATA_FINE_LANCIO")
private …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试为我的网站实施第三方身份验证功能.这是我从网上获得的"enableCORS"功能.它位于"Server.js"中.
var enableCORS = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
next();
}
};
var express = require("Express");
var url = require("url");
var http = require("http");
var app;
var port = process.argv[2];
app = express();
http.createServer(app).listen(port);
app.use(enableCORS)
Run Code Online (Sandbox Code Playgroud)
从我的网站,我发送一个httpGet请求到我的Server.js(我使用node -harmony server.js 3000在我的控制台中运行).这是httpGet函数:
function httpGet(URL) {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", URL, false);
xmlHttp.send(null);
return xmlHttp.response;
}
Run Code Online (Sandbox Code Playgroud)
我发送的请求是:
var items = JSON.parse(httpGet("http://localhost:3000/items"));
Run Code Online (Sandbox Code Playgroud)
这很好用,我的控制台说GET请求是成功的200代码.这个工作的唯一原因是因为我使用"enableCORS"功能. …
我目前正在使用Laravel和开发一个Web应用程序AngularJs.文档模块中的一个要求是,他们想要创建,更新像Google Docs或等文档Zoho Docs.
我用Google搜索但无法找到解决方案.
我该如何实现它?看来这是一项艰巨的任务.
我想读取properties文件密钥,我发现注释中有classpath要设置的属性@PropertySource:
@Configuration
@PropertySources({
@PropertySource("classpath:config.properties"),
@PropertySource("classpath:db.properties")
})
public class AppConfig {
//...
}
Run Code Online (Sandbox Code Playgroud)
属性文件应该放在哪里以及如何知道注释中的类路径?
我遇到了Java 1.7的GregorianCalender问题.我知道转移到Java 8或使用Joda可能会解决我的问题,但遗憾的是这不是一个选项.
所以我试图添加365天来计算一个结束日期(添加365天可能看起来很愚蠢而不只是添加一年,但这是我的客户要求的,甚至在多次询问他之后他想坚持下去,因为他想忽略闰年).
总的来说一切都运作良好,但在接下来的单元测试中,它失败了他和我的期望.我现在重新计算了几次,并使用各种工具来检查我的结果,但我无法确认java的计算.
这是我的单元测试失败,因为它返回错误的日期:
@Test
public void test(){
// Get a Gregorian Calendar
Calendar cal = GregorianCalendar.getInstance();
// Remove whatever was stored previously
cal.clear();
// Set calendar to 2004-10-23
cal.set( 2004, Calendar.OCTOBER, 23 );
// Add 365 days
cal.add( Calendar.DAY_OF_YEAR, 365 );
// Calendar should be at 2005-10-22 now
Assert.assertEquals( 2005, cal.get( Calendar.YEAR ) );
Assert.assertEquals( Calendar.OCTOBER, cal.get( Calendar.MONTH ) );
Assert.assertEquals( 22, cal.get( Calendar.DAY_OF_MONTH ) );
}
Run Code Online (Sandbox Code Playgroud)
它将失败:
java.lang.AssertionError: expected:<22> but was:<23>
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?