小编Dun*_*nes的帖子

classpath错误:无法找到org.aspectj.lang.JoinPoint

我正在使用maven来构建我的项目.它早先成功编译.当我这样做时,它已经开始出错了mvn clean install.

[ERROR] classpath error: unable to find org.aspectj.lang.JoinPoint (check that aspectjrt.jar is in your classpath)

下面是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.guavus</groupId>
    <artifactId>Exporter</artifactId>
    <version>atlas2.1</version>
    <packaging>jar</packaging>

    <name>Exporter</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <aspectj.version>1.6.10</aspectj.version>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>        
    </properties>

    <build>
         <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0-beta-2</version>
                <configuration>
                    <reportPlugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-javadoc-plugin</artifactId>
                            <version>2.7</version>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jxr-plugin</artifactId>
                            <version>2.1</version>
                            <configuration>
                                <aggregate>true</aggregate>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-report-plugin</artifactId>
                            <version>2.6</version>
                        </plugin>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>cobertura-maven-plugin</artifactId>
                            <version>2.4</version>
                            <configuration>
                                <formats>
                                    <format>xml</format>
                                    <format>html</format>
                                </formats>
                            </configuration>
                        </plugin>
                        <!--
                            plugin> <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-checkstyle-plugin</artifactId>
                            <version>2.6</version> </plugin …
Run Code Online (Sandbox Code Playgroud)

java classpath java-ee pom.xml maven

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

When using maven-release-plugin, why not just detect scm info from local repo?

As far as I am aware, in order to use the maven-release-plugin, you have to drop in an scm section into your POM file. E.g.:

<scm>
    <connection>scm:hg:ssh://hg@bitbucket.org/my_account/my_project</connection>
    <developerConnection>scm:hg:ssh://hg@bitbucket.org/my_account/my_project</developerConnection>
    <url>ssh://hg@bitbucket.org/my_account/my_project</url>
    <tag>HEAD</tag>
</scm>
Run Code Online (Sandbox Code Playgroud)

I understand this data is used to determine what to tag and where to push changes. But isn't this information already available if you have the code cloned/checked-out? I'm struggling a bit with the concept that I need to tell maven what code it needs to tag when it …

maven maven-release-plugin maven-scm-plugin

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

将"2013年2月1日星期五"转换为"2013-02-01"

如何在Java中执行此转换?

目前,我正在做:

public static String formatDate(String strDateToFormat) {
    try {
        SimpleDateFormat sdfSource = new SimpleDateFormat("EEEE, MMMM DD, YYYY");
        Date date = sdfSource.parse(strDateToFormat);
        SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
        return sdfDestination.format(date);
    } catch (ParseException pe) {
        System.err.println("Parse Exception : " + pe);
    }

    return null;
}
Run Code Online (Sandbox Code Playgroud)

但是,这会导致格式不正确.它给了我以下输出:

Friday, February 1, 2013 > 2013-01-04
Thursday, January 31, 2013 > 2013-01-03
Run Code Online (Sandbox Code Playgroud)

java date simpledateformat

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

在同步块结束时是否需要notifyAll()?

我曾经写过一个synchronized像以下一样的块:

synchronized(foobar) {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

但是,最近我看到有人写道:

synchronized(foobar) {
    // do something
    foobar.notifyAll();
}
Run Code Online (Sandbox Code Playgroud)

foobar.notifyAll();必要吗?如果我省略它会怎么样?

java

5
推荐指数
2
解决办法
2298
查看次数

如何在java中生成160位素数?

我想在java中生成一个160位的素数.我知道我必须循环遍历所有160位数字,对于任何数字n,我都必须检查它们是否可以被任何质数小于sqroot(n)或者通过任何素数测试整除Miller-Rabin test.我的问题是:

  1. 有没有特定的库可以做到这一点?

  2. 有没有其他(更好)的方法来做到这一点?

java primes

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

无法在maven-pmd-plugin 5.0.2中使用自定义规则集

我希望maven-pmd-plugin包含我指定的规则集并排除一些规则(特别是UselessParentheses)

就像在文档中描述的那样,我将以下内容放在pmd.xml中,该pmd.xml是所有模块的父级:

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <rulesets>
            <ruleset>/home/ubuntu/ruleset.xml</ruleset>
          </rulesets>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
Run Code Online (Sandbox Code Playgroud)

并准备了一个自定义规则集,如下所示:

  <!-- We'll use the entire rulesets -->
  <rule ref="rulesets/java/basic.xml"/>
  <rule ref="rulesets/java/imports.xml"/>
  <rule ref="rulesets/java/codesize.xml"/>
  <rule ref="rulesets/java/design.xml"/>
  <rule ref="rulesets/java/strings.xml"/>
  <rule ref="rulesets/java/unusedcode.xml"/>

  <!-- We want everything from this except some -->
  <rule ref="rulesets/java/unnecessary.xml">
    <exclude name="UselessParentheses"/>
  </rule>
Run Code Online (Sandbox Code Playgroud)

作为主要部分.

然而,当我跑步时,我mvn clean jxr:jxr pmd:check在报告中有"UselessParentheses".而且,用-Xshow来运行它

[DEBUG] Preparing ruleset: java-basic
[DEBUG] Before: java-basic After: java-basic.xml
[DEBUG] The resource 'rulesets/java/basic.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/basic.xml.
[DEBUG] Preparing …
Run Code Online (Sandbox Code Playgroud)

customization pmd maven-plugin maven

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

Maven bundle插件 - 如何添加主类

我有一个Maven项目mjbean只有一个依赖项:TestA.这是mjbean的pom.xml:

<groupId>com.mbean</groupId>
<artifactId>mjbean</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>

<build>
  <defaultGoal>install</defaultGoal>
  <plugins>
    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
        <instructions>
          <Main-Class>com.mbean.Main</Main-Class>
          <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
          <Embed-Transitive>true</Embed-Transitive>
          <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
          <Import-Package>*</Import-Package>
        </instructions>
      </configuration>
    </plugin>
  </plugins>
</build>

<name>mjbean</name>
<url>http://maven.apache.org</url>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.testa</groupId>
    <artifactId>TestA</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

主要课程非常简单:

package com.mbean;
import com.testa.Testcl;
public class Main {

public static void main(String[] args) {

    Testcl tcl = new Testcl();
    tcl.testmethod();
    }
}
Run Code Online (Sandbox Code Playgroud)

<Main-Class>com.mbean.Main</Main-Class>在maven-bundle-plugin中指定了主类.它与Eclipse运行良好.然后我使用Eclipse在目标文件夹中生成目标包.当我尝试在命令行中运行它时java -jar mjbean-0.0.1-SNAPSHOT.jar,我收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/testa/Testcl
at com.mbean.Main.main(Main.java:12) …
Run Code Online (Sandbox Code Playgroud)

java eclipse maven maven-bundle-plugin

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

如何将 zip 文件读取为字节数组,然后将字节数组转换回 zip 文件?

我曾尝试使用此代码将 ZIP 文件转换为字节数组:

private static byte[] readZipFile(String zipFnm)
// read in fnm, returning it as a single string
{

  FileInputStream fileInputStream=null;

  File file = new File(zipFnm);

  byte[] bFile = new byte[(int) file.length()];

  try{
    //convert file into array of bytes
    fileInputStream = new FileInputStream(zipFnm);
    fileInputStream.read(bFile);
    fileInputStream.close();
  }catch(Exception e){
    e.printStackTrace();
  }
  return bFile;
}  
Run Code Online (Sandbox Code Playgroud)

以及用于将字节数组转换回 ZIP 的代码,通过调用 writeByteToZip(fnm + ".zip");

private static String writeByteToZip(String outFnm)
{
  try {
    FileOutputStream fileOuputStream = new FileOutputStream(outFnm); 
    fileOuputStream.write(bFile);
    fileOuputStream.close();            

  } catch ( IOException iox ){
    iox.printStackTrace(); …
Run Code Online (Sandbox Code Playgroud)

java zip bytearray

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

将 Eclipse 配置为使用 javac 而不是 ECJ 进行编译?

我在使用 javac 编译器编译的 maven 项目中遇到了一些与 java8 相关的代码,但在 Eclipse 中给出了编译错误(我认为 ECJ 编译器不同于 javac)。

我在 Eclipse-Luna 中导入它:Import => Maven => Existsing Maven Project

作为快速修复,有没有办法让 Eclipse 在 maven 项目中使用 javac(从而禁用 ECJ 编译器)?

编辑:添加编译器差异的最小 poc 示例。

此代码使用javac 编译,但 List 初始化在 Eclipse 中给出错误:“此表达式的目标类型必须是功能接口”

package test;

import static java.util.Arrays.asList;

import java.util.List;

public class Test01 {

    private static final List<MyInterface> items = asList(() -> "123", () -> "456");

    public void test01() {
        System.out.println("Hello");
    }

    public interface MyInterface {
        String value();
    }
}
Run Code Online (Sandbox Code Playgroud)

如果添加类型转换,错误就会消失:

private …
Run Code Online (Sandbox Code Playgroud)

java eclipse javac eclipse-jdt java-8

5
推荐指数
0
解决办法
1409
查看次数

IntelliJ代码检查中的入口点是什么,我需要"修复"它们吗?

我正在使用IntelliJ IDEA.我尝试了它附带的"检查代码"功能,我想修复一个叫做"入口点"的东西.这与我的枚举和主要方法有关.我想知道入口点是什么以及如何解决该错误.

java static-analysis intellij-idea entry-point

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