在pom.xml文件中增加了htmlunit插件,传到服务器上使用mvn clean compile package -Dmaven.test.skip=true命令打包,出现错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.124 s
[INFO] Finished at: 2017-09-19T14:07:14+08:00
[INFO] Final Memory: 14M/171M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project XXX: Could not resolve dependencies for project com.orange:XXX:jar:0.0.1-SNAPSHOT:
Failed to collect dependencies at net.sourceforge.htmlunit:htmlunit:jar:2.17 -> xalan:xalan:jar:2.7.2 -> xalan:serializer:jar:2.7.2 ->
xml-apis:xml-apis:jar:1.3.04: Failed to read artifact descriptor for xml-apis:xml-apis:jar:1.3.04: Could not transfer artifact
xml-apis:xml-apis:pom:1.3.04 from/to central (https://repo.maven.apache.org/maven2):
/data/repo/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.pom.part.lock (No such file or directory) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
maven htmlunit
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.17</version>
</dependency>
在我本地打包都正常,只有在服务器上报错,经过排除发现xml-apis:jar所在目录的所有者是root,而我打包使用的用户是另一个,htmlunit要下载依赖包到xml-apis:jar所在的目录,因为权限不够所以报错了,改一下所属用户和组就行了
用maven创建的java项目在启动的时候找不到spring的配置文件,是java项目,不是web项目
解决办法是在pom.xml build 中增加一个插件:
<plugins>
<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>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.orange.task.StartMain</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
maven打包编译
mvn clean compile package -Dmaven.test.skip=true