简体   繁体   English

如何修复“导入com.dyuproject无法解析”错误

[英]How to fix “import com.dyuproject cannot be resolved” error

I'm fairly new to Java and especially new to Maven and specifically the protostuff project ( protostuff website ). 我是Java的新手,尤其是Maven的新手,尤其是protostuff项目( protostuff网站 )。 I need to use protostuff to serialize/deserialize XML to google's protobuf format. 我需要使用protostuff将XML序列化/反序列化为Google的protobuf格式。 I tried using the protobuf-java-format package, but there's a documented error in deserialization that is a show-stopper for me ( issue 37 ). 我尝试使用protobuf-java-format软件包,但是反序列化中有一个已记录的错误,这对我来说是一个制止符问题37 )。

So far I've done the following: 到目前为止,我已经完成了以下工作:

  1. Downloaded protostuff-1.3.1 & extracted it. 下载protostuff-1.3.1并解压缩。
  2. Ran mvn integration-test , mvn install and mvn package and all steps succeeded. 运行mvn integration-testmvn installmvn package ,所有步骤均成功。
  3. I then created a new maven project and included a proto as described here 然后,我创建了一个新的maven项目,并包含一个此处所述的原型。
  4. I then modified my pom.xml and ran protostuff:compile on the proto as described in the aforementioned link , generating the following Person.java file 然后,我修改了pom.xml并运行protostuff:compile上述链接中所述在proto上protostuff:compile ,生成以下Person.java文件

     // Generated by http://code.google.com/p/protostuff/ ... DO NOT EDIT! // Generated from foo.proto package com.example.foo; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.dyuproject.protostuff.ByteString; import com.dyuproject.protostuff.GraphIOUtil; import com.dyuproject.protostuff.Input; import com.dyuproject.protostuff.Message; import com.dyuproject.protostuff.Output; import com.dyuproject.protostuff.Schema; import com.dyuproject.protostuff.UninitializedMessageException; public final class Person implements Externalizable, Message<Person>, Schema<Person> { public enum Gender implements com.dyuproject.protostuff.EnumLite<Gender> { MALE(1), FEMALE(2); public final int number; private Gender (int number) { this.number = number; } public int getNumber() { return number; } public static Gender valueOf(int number) { switch(number) { case 1: return MALE; case 2: return FEMALE; default: return null; } } } public static Schema<Person> getSchema() { return DEFAULT_INSTANCE; } public static Person getDefaultInstance() { return DEFAULT_INSTANCE; } static final Person DEFAULT_INSTANCE = new Person(); static final String DEFAULT_MOTTO = ByteString.stringDefaultValue("When the cat is away, the mouse is alone!"); static final Gender DEFAULT_GENDER = Gender.MALE; private Integer id; private String name; private String motto = DEFAULT_MOTTO; private Gender gender; public Person() { } public Person( Integer id ) { this.id = id; } // getters and setters // id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } // name public String getName() { return name; } public void setName(String name) { this.name = name; } // motto public String getMotto() { return motto; } public void setMotto(String motto) { this.motto = motto; } // gender public Gender getGender() { return gender == null ? Gender.MALE : gender; } public void setGender(Gender gender) { this.gender = gender; } // java serialization public void readExternal(ObjectInput in) throws IOException { GraphIOUtil.mergeDelimitedFrom(in, this, this); } public void writeExternal(ObjectOutput out) throws IOException { GraphIOUtil.writeDelimitedTo(out, this, this); } // message method public Schema<Person> cachedSchema() { return this; } // schema methods public Person newMessage() { return new Person(); } public Class<Person> typeClass() { return Person.class; } public String messageName() { return Person.class.getSimpleName(); } public String messageFullName() { return Person.class.getName(); } public boolean isInitialized(Person message) { return message.id != null; } public void mergeFrom(Input input, Person message) throws IOException { for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this)) { switch(number) { case 0: return; case 1: message.id = input.readInt32(); break; case 2: message.name = input.readString(); break; case 3: message.motto = input.readString(); break; case 4: message.gender = Gender.valueOf(input.readEnum()); break; default: input.handleUnknownField(number, this); } } } public void writeTo(Output output, Person message) throws IOException { if(message.id == null) throw new UninitializedMessageException(message); output.writeInt32(1, message.id, false); if(message.name != null) output.writeString(2, message.name, false); if(message.motto != null && message.motto != DEFAULT_MOTTO) output.writeString(3, message.motto, false); if(message.gender != null) output.writeEnum(4, message.gender.number, false); } public String getFieldName(int number) { switch(number) { case 1: return "id"; case 2: return "name"; case 3: return "motto"; case 4: return "gender"; default: return null; } } public int getFieldNumber(String name) { final Integer number = __fieldMap.get(name); return number == null ? 0 : number.intValue(); } private static final java.util.HashMap<String,Integer> __fieldMap = new java.util.HashMap<String,Integer>(); static { __fieldMap.put("id", 1); __fieldMap.put("name", 2); __fieldMap.put("motto", 3); __fieldMap.put("gender", 4); } } 

I'm building this whole project in Eclipse (Luna release) and it gives the error "import com.dyuproject cannot be resolved" for the above file. 我正在Eclipse(Luna版本)中构建整个项目,它为上述文件给出了错误“无法解析导入com.dyuproject”。 I don't understand why it gives the error or how to find/install the package so Eclipse can see it. 我不明白为什么它会给出错误或如何找到/安装该软件包,以便Eclipse可以看到它。 Should Maven have built/provided that? Maven应该建立/提供吗?

I'm running CentOS release 6.4 (Final) on a VirtualBox VM: 我在VirtualBox VM上运行CentOS版本6.4(最终版):

uname -a Linux localhost.localdomain 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux ` uname -a Linux localhost.localdomain 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Looks like you are using incompatible protostuff-core and protostuff-maven-plugin versions. 似乎您使用的protostuff-coreprotostuff-maven-plugin版本不兼容。

Starting from version 1.1, protostuff uses package io.protostuff instead of com.dyuproject.protostuff . 从1.1版开始,protostuff使用包io.protostuff而不是com.dyuproject.protostuff Protostuff dependency version and protostuff maven plugin version should be equal (1.3.5 is the latest version). Protostuff依赖版本和Protostuff Maven插件版本应相等(最新版本为1.3.5)。

Here is an example of maven project that uses protostuff-maven-plugin for code generation. 是使用protostuff-maven-plugin进行代码生成的Maven项目的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM