由于国内网络原因,官方maven镜像源经常无法访问,全局设置maven镜像源:
vim ~/.m2/settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
将maven源修改为阿里云的镜像源。
2018年5月23日星期三
2018年4月28日星期六
migration-tooling项目的问题
国内的https://repo1.maven.org/maven2/连不上了,导致我们使用的https://github.com/bazelbuild/migration-tooling项目都无法运行。
解决方法:
在migration-tooling项目根目录的WORKSPACE文件最前面添加:
maven_server(
name = "default",
url = "http://maven.aliyun.com/nexus/content/groups/public/",
)
全局搜索项目中的MAVEN_CENTRAL_URL,将https://repo1.maven.org/maven2/替换为http://maven.aliyun.com/nexus/content/groups/public/
然后就可以正常运行bazel run //generate_workspace -- --xxx 了。
解决方法:
在migration-tooling项目根目录的WORKSPACE文件最前面添加:
maven_server(
name = "default",
url = "http://maven.aliyun.com/nexus/content/groups/public/",
)
全局搜索项目中的MAVEN_CENTRAL_URL,将https://repo1.maven.org/maven2/替换为http://maven.aliyun.com/nexus/content/groups/public/
然后就可以正常运行bazel run //generate_workspace -- --xxx 了。
2017年2月9日星期四
Exclude dependency from maven assembly plugin
在<dependency>...</dependency>中增加<scope>provided</scope>即可。
2016年10月26日星期三
maven 为测试环境、生产环境等不同环境打包
参考http://www.blogjava.net/fancydeepin/archive/2015/06/27/maven-p.html
在pom中添加:
<profiles>
<profile> <!-- 可以通过 -P ID 来激活 -->
<id>PROD</id> <!-- ID 标识符 -->
<properties>
<env>PROD</env> <!-- properties 定义 key-value, 这里 key 是 env, value 是 PROD -->
</properties>
<activation>
<activeByDefault>true</activeByDefault> <!-- 默认激活 -->
</activation>
</profile>
<profile> <!-- 可以通过 -P ID 来激活 -->
<id>TEST</id> <!-- ID 标识符 -->
<properties>
<env>TEST</env> <!-- properties 定义 key-value, 这里 key 是 env, value 是 TEST -->
</properties>
</profile>
</profiles>
编译时使用mvn install -P ID即可。
在pom中添加:
<profiles>
<profile> <!-- 可以通过 -P ID 来激活 -->
<id>PROD</id> <!-- ID 标识符 -->
<properties>
<env>PROD</env> <!-- properties 定义 key-value, 这里 key 是 env, value 是 PROD -->
</properties>
<activation>
<activeByDefault>true</activeByDefault> <!-- 默认激活 -->
</activation>
</profile>
<profile> <!-- 可以通过 -P ID 来激活 -->
<id>TEST</id> <!-- ID 标识符 -->
<properties>
<env>TEST</env> <!-- properties 定义 key-value, 这里 key 是 env, value 是 TEST -->
</properties>
</profile>
</profiles>
编译时使用mvn install -P ID即可。
2016年10月17日星期一
pom中引入本地jar包
将jar包放入工程目录下,增加dependency:
<dependency>
<groupId>xxx.xxx.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/xxx.jar</systemPath>
</dependency>
<dependency>
<groupId>xxx.xxx.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/xxx.jar</systemPath>
</dependency>
2016年7月30日星期六
解决mvn test没有运行Scala Test
http://stackoverflow.com/questions/13036561/trying-to-get-scalatest-working-there-are-no-tests-to-run-when-doing-mvn-tes
在pom的plugin中增加:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
参考http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin
在pom的plugin中增加:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
参考http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin
2016年6月27日星期一
maven打包可执行文件
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.mobvoi.mqtt.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.mobvoi.mqtt.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
2016年3月25日星期五
Maven报错Missing artifact jdk.tools:jdk.tools:jar:1.8
参考:http://blog.csdn.net/u013281331/article/details/40824707
在pom.xml中加上依赖:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.8.0_65/lib/tools.jar</systemPath>
</dependency>
解决。
在pom.xml中加上依赖:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.8.0_65/lib/tools.jar</systemPath>
</dependency>
解决。
创建maven工程的一个问题
在eclipse中创建maven工程出现这样错误:
creating maven-archetype-quickstart has encountered a problem
unable to create project from archetype ...
尝试在命令行创建也遇到错误,这次的错误信息更多一些:
Unable to add module to the current project as it is not of packaging type 'pom' -> [Help 1]
原因:
创建工程的目录中存在了pom.xml文件,所以无法创建。
creating maven-archetype-quickstart has encountered a problem
unable to create project from archetype ...
尝试在命令行创建也遇到错误,这次的错误信息更多一些:
Unable to add module to the current project as it is not of packaging type 'pom' -> [Help 1]
原因:
创建工程的目录中存在了pom.xml文件,所以无法创建。
windows中解决eclipse中maven install时Unsupported major.minor version 51.0问题
maven install时报错:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
对应版本如下:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
maven install时要求jre版本必须在7以上,我没有导入自己安装的jre的路径,eclipse自带的是1.6版本的。
解决:在Windows -> Preferences中Java选项下的Installed JREs设置为JDK1.7以上的版本即可。
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
对应版本如下:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
maven install时要求jre版本必须在7以上,我没有导入自己安装的jre的路径,eclipse自带的是1.6版本的。
解决:在Windows -> Preferences中Java选项下的Installed JREs设置为JDK1.7以上的版本即可。
订阅:
博文 (Atom)