管理工具---Maven系列(一)编译问题

问题:Maven打包编译错误工作区间设置编码格式gbk可以utf-8不可以
错误如下:
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ins-service: Compilation failure
[ERROR] javac: �Ҳ����ļ�: E:\SVN3\20160918JunKang_Dev\JKDS\05源代�?后端\v1.0\parent\ins-service\src\main\java\com\junk\enums\FileUploadEnum.java
[ERROR] �÷�: javac
[ERROR] -help �����г����ܵ�ѡ��
[ERROR] -> [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/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :ins-service
解决办法:
根据出现的乱码发现应该推测到格式编码问题,所以验证下,改工作区间编码格式为gbk呀呀,竟然好了。再改会utf-8格式呀呀又出错了,很奇怪,推测问题是两种:
一种是原来的gbk现在utf-8但是很明显问题不对路,但是还是提供一种解决方式将gbk代码改成utf-8代码
代码如下:

package org.xc.binny;

import java.io.File;
import java.util.Collection;

import org.apache.commons.io.FileUtils;

public class GBK2UTF8App {
    /**
     * 将制定目录下的所有Java源文件的编码格式从GBK修改为UTF-8
     */
    public static void main(String[] args) throws Exception {
        //GBK编码格式源码路径
        String srcDirPath = "C:\\Users\\Wolf\\Desktop\\src";
//      //转为UTF-8编码格式源码路径E:\SVN3\20160918JunKang_Dev\JKDS\05源代码\后\v1.0\parent\ins-service\src\main\java\com\junk
        String utf8DirPath =  "C:\\Users\\Wolf\\Desktop\\src";
    //      String srcDirPath = "E:\\SVN3\\20160918JunKang_Dev\\JKDS\\05源代码\\后端\\v1.0\\parent\\ins-common\\src\\main\\java\\com\\common";
//      //转为UTF-8编码格式源码路径E:\SVN3\20160918JunKang_Dev\JKDS\05源代码\后\v1.0\parent\ins-service\src\main\java\com\junk
//      String utf8DirPath = "E:\\SVN3\\20160918JunKang_Dev\\JKDS\\05源代码\\后端\\v1.0\\parent\\ins-common\\src\\main\\java\\com\\common";
//      

        //获取所有java文件
        Collection<File> javaGbkFileCol =  FileUtils.listFiles(new File(srcDirPath), new String[]{"java"}, true);
        int count=0;
        for (File javaGbkFile : javaGbkFileCol) {

            //UTF8格式文件路径
            String utf8FilePath = utf8DirPath+javaGbkFile.getAbsolutePath().substring(srcDirPath.length());
            //使用GBK读取数据,然后用UTF-8写入数据
//          FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));     
            FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));     

            count++;
            System.out.println("执行文件次数"+count);
        }

    }


}

jar包:commons-io-1.4.jar
第二种是maven编译的问题:
搜罗pom文件关于编译的问题原来:
maven中的plugins 和 pluginManagement、dependencies和dependencyManagement。这两个后者都需要放置在父文件里面,前者在子文件里。他们区别是:
maven会在当前项目中加载plugins声明的插件;

pluginManagement是表示插件声明,即你在项目中的pluginManagement下声明了插件,maven不会加载该插件,pluginManagement声明可以被继承。

pluginManagement的一个使用案例是当有父子项目的时候,父项目中可以利用pluginManagement声明子项目中需要用到的插件, 之后,当某个或者某几个子项目需要加载该插件的时候,就可以在子项目中plugins节点只配置 groupId 和 artifactId就可以完成插 件的引用。
pluginManagement主要是为了统一管理插件,确保所有子项目使用的插件版本保持一致。
哈哈问题找到了那么改一下吧:

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
......
</plugins>
<pluginManagement>
改成:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
......
</plugins>
<build>

那么原因到底是什么呢为啥呢gbk可以通过,utf-8不可以呢
由于系统默认编码是GBK,因此默认可以gbk通过编译。

具体参看maven-war-plugin插件的文档,里面有编码相关的设置:
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#resourceEncoding
加群一起进步: 300458205

发布了210 篇原创文章 · 获赞 243 · 访问量 26万+
展开阅读全文

maven项目编译总是报错DependencyResolutionException

06-27

## 项目代码不报错,照网上的搜索结果,分别用了两种方式编译该maven项目 ## 第一种:命令行,提示success ![图片说明](https://img-ask.csdn.net/upload/201606/27/1467030050_633970.png) ## 第二种:run as--》maven bulid--》输入compile ![图片说明](https://img-ask.csdn.net/upload/201606/27/1467030096_859152.jpg) ![图片说明](https://img-ask.csdn.net/upload/201606/27/1467030108_647485.jpg) ## 这个错的详细信息是: [ERROR] Failed to execute goal on project SSM01: Could not resolve dependencies for project com.cailikun:SSM01:war:0.0.1-SNAPSHOT: Failed to collect dependencies at mysql:mysql-connector-java:jar:6.0.3: Failed to read artifact descriptor for mysql:mysql-connector-java:jar:6.0.3: Could not transfer artifact mysql:mysql-connector-java:pom:6.0.3 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org -> [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 ## 这个异常信息里一直在提mysql-connector-java这个jar包是几个意思?我在pom.xml里换把这个jar包换个版本也不行 问答

运行Tomcat出错,[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

09-18

``` [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building taotao-manage-web 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ taotao-manage-web >>> [WARNING] The POM for com.taotao.manage:taotao-manage-service:jar:1.0.0-SNAPSHOT is missing, no dependency information available [WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.732 s [INFO] Finished at: 2019-09-18T09:04:04+08:00 [INFO] Final Memory: 6M/121M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project taotao-manage-web: Could not resolve dependencies for project com.taotao.manage:taotao-manage-web:war:1.0.0-SNAPSHOT: Could not find artifact com.taotao.manage:taotao-manage-service:jar:1.0.0-SNAPSHOT -> [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 install 出错!!!求解决方法

10-18

在maven install时,报错 ``` [INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-parseable POM C:\Users\80883846\.m2\repository\org\springframework\boot\spring-boot-starter-parent\1.5.7.RELEASE\spring-boot-starter-parent-1.5.7.RELEASE.pom: Expected root element 'project' but found 'html' (position: START_TAG seen <html>... @1:6) @ C:\Users\80883846\.m2\repository\org\springframework\boot\spring-boot-starter-parent\1.5.7.RELEASE\spring-boot-starter-parent-1.5.7.RELEASE.pom, line 1, column 6 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.hkt.bpu.asd.noss:pcms-admin-portal:1.0.0 (G:\EclipseWorkspace\PCMS Admin Portal\trunk\pom.xml) has 1 error [ERROR] Non-parseable POM C:\Users\80883846\.m2\repository\org\springframework\boot\spring-boot-starter-parent\1.5.7.RELEASE\spring-boot-starter-parent-1.5.7.RELEASE.pom: Expected root element 'project' but found 'html' (position: START_TAG seen <html>... @1:6) @ C:\Users\80883846\.m2\repository\org\springframework\boot\spring-boot-starter-parent\1.5.7.RELEASE\spring-boot-starter-parent-1.5.7.RELEASE.pom, line 1, column 6 -> [Help 2] [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/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException ``` 请问这个问题该怎么解决? 问答

maven install时出错望好心人解决一下。小弟先谢谢了

01-20

------------------------------------------------------- T E S T S ------------------------------------------------------- Forking command line: cmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0\jre\bin\java" -jar E:\工作\我的代码\workspaceCollab2\AAA\target\surefire\surefirebooter4742801322268775008.jar E:\工作\我的代码\workspaceCollab2\AAA\target\surefire\surefire6598622082065573176tmp E:\工作\我的代码\workspaceCollab2\AAA\target\surefire\surefire_07796347708207276805tmp" ����: ���Դ��ļ�E:\?�����\???��??\workspaceCollab2\AAA\target\surefire\surefirebooter4742801322268775008.jʱ����������� Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 8.642 s [INFO] Finished at: 2016-01-20T16:45:04+08:00 [INFO] Final Memory: 15M/38M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project eosgi-report: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project eosgi-report: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) at org.codehaus.classworlds.Launcher.main(Launcher.java:46) Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:143) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 20 more Caused by: java.lang.RuntimeException: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.close(ForkClient.java:257) at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:301) at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:116) at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:740) at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAllProviders(AbstractSurefireMojo.java:682) at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:648) at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:586) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132) ... 21 more [ERROR] [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/PluginExecutionException 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 护眼 设计师: 闪电赇

分享到微信朋友圈

×

扫一扫,手机浏览