小编Luk*_*asz的帖子

在Eclipse中使用自动添加的导入时,包名称错误

我将几个Maven项目转换为一个Eclipse工作区.当我在Eclipse下编辑代码时,我有时会使用CTRL+ SHIFT+ M组合键自动将导入添加到工作区中项目的类中.但不知何故,他们添加如下:

import src.main.java.com.mycompany;
Run Code Online (Sandbox Code Playgroud)

而我要导入的真正包装是com.mycompany.这必须是Eclipse中的一些配置来解决这个问题,但我很困惑.但是,这个问题非常烦人.

编辑:

我忘了提到Eclipse文件是使用mvn eclipse:eclipse命令生成的.

在Eclipse项目下似乎配置正确.它的源文件夹设置如下:

  • 的src /测试/ JAVA
  • SRC /测试/资源
  • 的src /主/ JAVA
  • 的src/main /资源

除了按CTRL+ SHIFT+ M键的情况外,Eclipse下的所有内容都能正常工作

java eclipse

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

DDD中的多对多关系

我是DDD的新手,而且我遇到了多对多的关系.例如,我们有两个聚合根 - 任务和工人.

合同绝对不是聚合根,因为没有Task和Worker就没有意义.所以,它应该是某些聚合的一部分.但它属于哪个聚合体?我们需要知道所有工作合同的汇总成本和所有工人合同的汇总成本.我很自然地在Task和Worker中收集合同.

好吧,我可以将费用计算转移到域名服务,但我担心这是贫穷模型的一步.有没有通用的方法来处理多对多关系并保留覆盖域模型?

谢谢!

类图

c# domain-driven-design

19
推荐指数
2
解决办法
3131
查看次数

@SuppressWarnings( "串行")

我有一个问题,因为我有点困惑(或者我可能没注意到一些明显的东西).假设我有一些包含很多类的源代码,这些类包含大量像这样定义的静态字段:

public final class ConverterTYPE  {
    private final static HashMap<String, Byte> STRING_MAP = new HashMap<String, Byte>() {
        {
            put("A", new Byte((byte)12));
            put("B", new Byte((byte)13));
        }
    };

}
Run Code Online (Sandbox Code Playgroud)

众所周知,静态字段不会被序列化.

但是,Java(和Eclipse)抱怨"可序列化类没有声明类型为long的静态最终serialVersionUID字段".为什么他们不能注意到静态不会被序列化?

接下来的问题是:用这个问题@SuppressWarnings("serial")摆脱所有这些警告是否是正确的解决方案?

编辑:

我的类都没有实现Serializable接口(或者没有超类).Eclipse正在指出HashMap<String, Byte>它的警告.为什么不检测到它是静态场?

java serialization suppress-warnings

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

在JodaTime中生成日期范围

我需要检查数组列表中是否存在日期(字符串).

我有两个日期,首先我需要在这两个日期之间生成日期范围并将它们存储在一个数组中.这就是我在做的事情.

DateTimeFormatter dateFromatter= DateTimeFormat.forPattern("MM/dd/yyyy");

DateTime startDate= formatter.parseDateTime("01/02/2012");
DateTime endDate= formatter.parseDateTime("01/31/2012");

 List<LocalDate> dates = new ArrayList<LocalDate>();


  int days = Days.daysBetween(startDate, endDate).getDays();
  for (int i=0; i < days; i++) {
Run Code Online (Sandbox Code Playgroud)

这是我遇到问题的地方.

Type mismatch: cannot convert from DateTime to LocalDate

>   LocalDate listOfDates =
> startDate.withFieldAdded(DurationFieldType.days(), i);
> dates.add(listOfDates);

  }
Run Code Online (Sandbox Code Playgroud)

java jodatime

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

使用maven-antrun-plugin的Maven Ant BuildException ...无法找到javac编译器

我正在尝试让Maven为一些遗留代码调用ANT构建.ant构建通过ant正确构建.但是,当我使用maven ant插件调用它时,它失败并出现以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run      (default) on project CoreServices: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:158: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:62: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:33: The following error occurred while executing this line:
[ERROR] C:\dev\projects\ods\build.xml:41: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] …
Run Code Online (Sandbox Code Playgroud)

java maven-plugin maven

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

如何强制生成@XmlSeeAlso注释?

我正在使用 JAXB 从几个 XSD 文件生成 Java 代码。然后,在 OSGi 容器内,我将 XML 文件解组为生成的代码。XSD 使用 xsd:any 元素:

<xsd:complexType name="GetReservationRSType">
    <xsd:sequence>
        <xsd:element name="Errors" type="pnrb:Errors.PNRB"
            minOccurs="0" />
        <xsd:choice>
            <xsd:element name="Reservation" type="pnrb:Reservation.PNRB"
                minOccurs="0" />
            <xsd:element name="Content" minOccurs="0">
                <xsd:complexType>
                    <xsd:choice>
                        <xsd:any processContents="lax" />
                    </xsd:choice>
                </xsd:complexType>
            </xsd:element>
        </xsd:choice>
    </xsd:sequence>
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)

我在使其在生产代码中工作时遇到了几个问题,但最终当我手动添加 @XmlSeeAlso 注释(@XmlSeeAlso(value = { OTATravelItineraryRS.class })在下面的代码中)时解决了它:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GetReservationRSType", propOrder = {
    "warnings",
    "errors",
    "reservation",
    "content"
})
@XmlSeeAlso({
    GetReservationRS.class
})
public class GetReservationRSType {

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "any"
    }) …
Run Code Online (Sandbox Code Playgroud)

xsd jaxb

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

如何使用Groovy添加XML属性?

我需要在Groovy中将@属性添加到XML片段的根元素中.我想用XmlSlurper.怎么做?添加元素很容易.

groovy

4
推荐指数
1
解决办法
7147
查看次数

了解java中的instanceof以及if条件?

我不确定树(引用变量)如何在我的示例程序53,00中成为对象Tree的实例?我期待"Pine"和"oops"作为输出,但为什么"Tree"包含在输出中?我还没有给Tree tree = new Tree().

    class Tree{}  
class Pine extends Tree{}  
class Oak extends Tree{}  
public class forrest {    

    public static void main( String[] args )      
    {    
        Tree tree = new Pine();   


        if( tree instanceof Pine )      
            System.out.println( "Pine" );   
        if( tree instanceof Tree )       
            System.out.println( "Tree" );  
        if( tree instanceof Oak )      
            System.out.println( "Oak" );   
        else System.out.println( "Oops" );  
    }  
}
Run Code Online (Sandbox Code Playgroud)

java instanceof

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

Java For 循环到递归函数中

public class For {
 public static void main(String[] args){
          for(int i=2; i<=1024; i *= 2){
           System.out.println("Count is: " + i);
      }
 }




public class While {
    public static void main(String[] args){
        int i = 1;
        while (i < 1024) {
            i *= 2;
            System.out.println("Count is: " + i);
      }
 }


public class DoWhile {
     public static void main(String[] args){
        int i = 1;
        if (i < 1024) {
            do { i*=2;
                System.out.println("Count is: " + i);
            } while (i < …
Run Code Online (Sandbox Code Playgroud)

java recursion for-loop while-loop

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

本地 JMX 调用失败并出现 ClassCastException

我正在尝试使用以下简单代码在本地调用 JMX 服务。它与 JConsole 一起工作得很好,但是在命令行下它会在粘贴代码的最后一行抛出异常。

    String serviceURL = "service:jmx:rmi:///jndi/rmi://localhost:" + configuration.getJmxPort();
    String[] credentials = new String[]{configuration.getUsername(), configuration.getPassword()};
    Map<String, String[]> attributes = new HashMap<String, String[]>();
    attributes.put("jmx.remote.credentials", credentials);

    JMXServiceURL jmxUrl = new JMXServiceURL(serviceURL);
    jmxCon = JMXConnectorFactory.connect(jmxUrl, attributes);
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪如下所示:

java.lang.ClassCastException: com.sun.jndi.rmi.registry.RegistryContext cannot be cast to javax.management.remote.rmi.RMIServer
    at javax.management.remote.rmi.RMIConnector.narrowJRMPServer(RMIConnector.java:1897)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1892)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
    at com.aaa.aaa.aaa.jmx.AaaJmxClient.main(AaaJmxClient.java:36)
Run Code Online (Sandbox Code Playgroud)

java jmx

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