jprotobuf icon indicating copy to clipboard operation
jprotobuf copied to clipboard

jprotobuf动态编译依赖打到一个包内,通过java -jar执行Bug

Open lijunyong opened this issue 8 years ago • 22 comments

https://github.com/Baidu-ecom/Jprotobuf-rpc-socket/issues/38

lijunyong avatar Sep 13 '16 06:09 lijunyong

@jhunters 有好几个提交的issue都存在这个问题

lijunyong avatar Sep 13 '16 07:09 lijunyong

这个问题会集中跟进一下,谢谢!

jhunters avatar Sep 13 '16 07:09 jhunters

@jhunters 嗯,能给个邮箱吗?

lijunyong avatar Sep 13 '16 07:09 lijunyong

你留一下你的邮箱,我们会回复一个你

jhunters avatar Sep 13 '16 08:09 jhunters

@jhunters [email protected]

lijunyong avatar Sep 13 '16 08:09 lijunyong

Spring boot 生成的jar在启动时,会使用一个叫 org.springframework.boot.loader.LaunchedURLClassLoader 的classloader,这个classloader的加载类中,不能查找到相关的类。动态编译拿到的这个classloader,直接导致失败. 这个是否有解决方案,还需要继续跟进spring boot的相关实现.

现在可以通地增加预编译插件的方式解决

        <plugin>
            <groupId>com.baidu</groupId>
            <artifactId>jprotobuf-precompile-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                <filterClassPackage>com</filterClassPackage>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>precompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>   

注意上面标黄的设置: filterClassPackage 是需要预编译的package前缀

jhunters avatar Sep 18 '16 03:09 jhunters

预编译插件中引入的jprotobuf 1.9.4的版本,不支持枚举??

hehe3547 avatar Oct 25 '16 07:10 hehe3547

这个版本支持枚举的,请问在使用中,出现什么错误?

jhunters avatar Oct 25 '16 07:10 jhunters

@Data class HelloReqData extends RequestInfo { @Protobuf(fieldType = FieldType.STRING, order = 2, description = "请求字符列子") private String req; @Protobuf(fieldType = FieldType.ENUM, order = 3, description = "测试enum") private BankCodeEnum bankCodeEnum; @Protobuf(fieldType = FieldType.OBJECT, order = 4, description = "测试list") private List<DetailData> details; @Protobuf(fieldType = FieldType.OBJECT, order = 5,description = "测试message") private DetailData reqDetail; @Protobuf(fieldType = FieldType.STRING, order = 6, description = "测试list") private List<String> listString; @Protobuf(fieldType = FieldType.INT32, order = 7, description = "测试list") private List<Integer> listInt; @Protobuf(fieldType = FieldType.INT64, order = 8) private long reqData; }

这个Bean,预编译时不能生成class文件,如果把FieldType.ENUM 去掉是可以的.

hehe3547 avatar Oct 25 '16 11:10 hehe3547

测试后没有发现你所说的问题, 如果在使用新的jprotobuf-precompile-plugin,也可以用1.2.3版本,使用了最新的jprotobuf。 不过用你的代码测试,发一个问题就是你的 List是必须要有泛型可以正常运行的

jhunters avatar Oct 25 '16 12:10 jhunters

我用的是jprotobuf 2.0.1的版本.和这个有关吗?没找到jprotobuf-precompile-plugin 1.2.3这个版本.

hehe3547 avatar Oct 25 '16 12:10 hehe3547

1.2.3刚发布,大概再过十分钟可以同步到官方库。 2.0.1是1.x版本是有冲突的,2.0.1是针对protobuf 3.x版本开发。 我明天同步发布一个支持2.x的 编译插件吧。发布后再回复

jhunters avatar Oct 25 '16 12:10 jhunters

你好 jprotobuf-precompile-plugin 2.0.0包,发现有个依赖包是错的 , 这个groupId是不是错了 <groupId>jboss</groupId> <artifactId>javassist</artifactId> jar 3.8.0.GA

hehe3547 avatar Oct 27 '16 01:10 hehe3547

的确,是我们私有maven仓库的问题,需要统一改到这下面 http://repo1.maven.org/maven2/javassist/javassist/

jhunters avatar Oct 27 '16 01:10 jhunters

还没有提交新的jprotobuf-precompile-plugin版本?

hehe3547 avatar Oct 27 '16 05:10 hehe3547

http://repo1.maven.org/maven2/com/baidu/jprotobuf-precompile-plugin/2.0.0/

jhunters avatar Oct 27 '16 05:10 jhunters

麻烦能再提交一个新的版本吧.修改一下这个包javassist的依赖.谢谢.

hehe3547 avatar Oct 27 '16 06:10 hehe3547

插件不依赖javassist的呀

jhunters avatar Oct 27 '16 07:10 jhunters

[ERROR] Failed to execute goal com.baidu:jprotobuf-precompile-plugin:2.0.0:precompile (default) on project interface: Execution default of goal com.baidu:jprotobuf-precompile-plugin:2.0.0:precompile failed: Plugin com.baidu:jprotobuf-precompile-plugin:2.0.0 or one of its dependencies could not be resolved: Fa ilure to find jboss:javassist:jar:3.8.0.GA in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

mvn clean compile 出这个错误

hehe3547 avatar Oct 27 '16 14:10 hehe3547

已修复 ,使用2.0.1版本即可

jhunters avatar Oct 28 '16 07:10 jhunters

已修复 ,使用2.0.1版本即可

openjdk11 jprotobuf打到jar内,在windows运行,JdkCompiler会设置jar内的路径,但是路径是file:开头,WindowsPathParser.normalize会抛出异常java.nio.file.InvalidPathException: Illegal char <:> at index 4:

whyzq avatar Apr 12 '22 05:04 whyzq

Illegal char <:> at index 4

jdk17也有这个问题,在windows系统直接运行jar会这样,但是用idea跑就不会

chenmaochang avatar Aug 16 '23 09:08 chenmaochang