发表于: 2017-09-16 23:27:30

1 839


今天完成的事
使用linux命令跑main方式
[root@iZwz9gb6l1wi8unt1iacqoZ ~]# java -jar linux1-1.0-SNAPSHOT.jar
这是我的第一个Java Application 程序!运行成功了
明天计划的事
测试一下不关闭连接池的时候,在Main函数里写1000个循环调用会出现什么情况
测试一下连接DB中断后TryCatch是否能正常处理
碰到的问题
1.java运行jar命令提示没有主清单属性
解决方法
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Test</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
需要借鉴的可以把<mainClass>Test</mainClass>里的Test改为自己main方法所在类的全路径
解决方法2
解压jar包,用记事本打开MANIFEST.MF
添加一行
MainClass: main类名
注:这里Main-Class:要空一格写上你的class文件名。如果你没有空格的话,还是问题是解决不了的。
2.想用test方法测试的时候碰上报错,报错原因如下
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
解决方法
这是由于junit版本过高,比以前的版本少了一些类,添加hamcrest-core依赖包可以解决
3.想尝试在linux下创建一个maven项目
mvn archetype:create -DgroupId=helloworld -DartifactId=helloworld
报错
Error:Could not find goal 'create' in plugin org.apache.maven.plugins:maven-archetype-plugin:3.0.1 among available goals crawl, create-from-project, generate, help, integration-test, jar, update-local-catalog -> [Help 1]
解决方法
把create替换为generate
原因
create is deprecated in maven 3.0.5 and beyond,在maven3.0.5以上版本舍弃了create,使用generate生成项目
输入后自动下载了很多东西到服务器上,最后会提示输入
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1033
这是要用户选择创建什么类型的项目,maven 会根据选择将项目的基本框架搭建好。由于是为了测试 maven 这里可以直接选择默认的项目(直接按回车)
4.尝试了一些方法但是动态打包失败
这是我使用的插件
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Test</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
收获
对怎么使用linux感到非常迷茫,如果是pc上还可以装图形交互,服务器上都是命令行交流,感到非常不适应



返回列表 返回列表
评论

    分享到