java.lang.NoClassDefFoundError: cc/moecraft/icq/PicqConfig
G-H-Li opened this issue · comments
maven生成jar之后,无法检测到包
默认打包的 jar 里面就只有你写的东西呀w
大概有两种方式解决啦w
- Shade - 把所有导入的包混在你的 jar 里面w
这样的好处是方便, 一个 jar 就能运行. - Copy-dependencies - 把所有导入的包单独导出w
这样的好处是如果要经常更新的话, 上传的 jar 可以很小, 但是有点麻烦.
Shade 的例子:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>org.hydev.something.Main</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</plugin>
</plugins>
Copy-dependencies 的例子:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>org.hydev.something.Main</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
Copy-dependencies 方式的启动脚本:
java -cp "YourJar.jar:./libs/*" sample.package.Main
明白了,我对maven打包的使用挺不熟的
现在还有一个问题啊
Exception in thread "main" com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2 path $ at com.google.gson.JsonParser.parse(JsonParser.java:65) at com.google.gson.JsonParser.parse(JsonParser.java:45) at cc.moecraft.icq.sender.IcqHttpApi.send(IcqHttpApi.java:111) at cc.moecraft.icq.sender.IcqHttpApi.sendReturnRaw(IcqHttpApi.java:135) at cc.moecraft.icq.sender.IcqHttpApi.send(IcqHttpApi.java:161) at cc.moecraft.icq.sender.IcqHttpApi.send(IcqHttpApi.java:175) at cc.moecraft.icq.sender.IcqHttpApi.getLoginInfo(IcqHttpApi.java:677) at cc.moecraft.icq.accounts.BotAccount.<init>(BotAccount.java:37) at cc.moecraft.icq.PicqBotX.addAccount(PicqBotX.java:219) at cc.moecraft.icq.PicqBotX.addAccount(PicqBotX.java:199) at com.assistant.AssistantApplication.main(AssistantApplication.java:39)
看上去貌似是jdk内部解析json的问题
现在还有一个问题啊
Exception in thread "main" com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2 path $ at com.google.gson.JsonParser.parse(JsonParser.java:65) at com.google.gson.JsonParser.parse(JsonParser.java:45) at cc.moecraft.icq.sender.IcqHttpApi.send(IcqHttpApi.java:111) at cc.moecraft.icq.sender.IcqHttpApi.sendReturnRaw(IcqHttpApi.java:135) at cc.moecraft.icq.sender.IcqHttpApi.send(IcqHttpApi.java:161) at cc.moecraft.icq.sender.IcqHttpApi.send(IcqHttpApi.java:175) at cc.moecraft.icq.sender.IcqHttpApi.getLoginInfo(IcqHttpApi.java:677) at cc.moecraft.icq.accounts.BotAccount.<init>(BotAccount.java:37) at cc.moecraft.icq.PicqBotX.addAccount(PicqBotX.java:219) at cc.moecraft.icq.PicqBotX.addAccount(PicqBotX.java:199) at com.assistant.AssistantApplication.main(AssistantApplication.java:39)
看上去貌似是jdk内部解析json的问题
这个问题在win系统中没问题,但是在ubuntu上跑有问题。运行方式是采用jar
报了 Json 语法错误哇w
是端口连不上的问题吧...
因为添加账号的时候会自动测试连接呀w
测试连接如果返回的不是 JSON 的话就会这样报错啦w
是的,刚刚我又重新测试了,应该是docker的端口配置问题