GVKun编程网logo

高效建立健壮的Android应用-Maven Android 开发

4

最近很多小伙伴都在问高效建立健壮的Android应用-MavenAndroid开发这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展maven项目配置maven私服,从私服下载jar

最近很多小伙伴都在问高效建立健壮的Android应用-Maven Android 开发这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展maven 项目配置 maven 私服,从私服下载 jar、AspectJ 注释在 JAVA maven 项目不是 spring 项目中不起作用 注解必须具有 RUNTIME 范围方面必须有 @Aspect 注释避免双日志输出添加缺少的 Maven 插件执行删除多余的 AspectJ 依赖确保旧的 AspectJ Maven 插件使用最新的 AspectJ 编译器、eclipse maven build、maven clean、maven install和maven test的区别 精析、Eclipse 使用 Maven 创建 Web 时错误:Could not resolve archetype org.apache.maven.archetypes:maven-ar等相关知识,下面开始了哦!

本文目录一览:

高效建立健壮的Android应用-Maven Android 开发

高效建立健壮的Android应用-Maven Android 开发

高效建立健壮的Android应用

第一次写(翻译)这么长的文章,请多包含. 本标题纯粹是别人的广告语,它说他可以

  1. 让你开发更加迅速
  2. 让你的应用更加强壮
  3. 提高应用的质量
  4. 构建你的企业解决方案
  5. 而且还是免费开源(我加的)

它包含以下组件:

  1. 日志

     import de.akquinet.android.androlog.Log;
     import android.app.Activity;
     import android.os.Bundle;
    
     public class MyActivity extends Activity {
         /** Called when the activity is first created. */
         @Override
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
    
             // Initializes androlog
             // This will read /sdcard/my.application.properties
             Log.init(this);
    
             // Log a message
             Log.i(this, "This is a logged message");
    
             setContentView(R.layout.main);
         }
     }
    
  2. 快速测试

     public void testValidAuth() throws Exception {
     	activity().view().withId(R.id.username).setText("testuser");
     	activity().view().withId(R.id.password).setText("testpw");
    
     	activity().view().withId(R.id.buttonSubmit).click();
    
     	NextActivity nextActivity = await().activity(
         	NextActivity.class, 10, TimeUnit.SECONDS);
     		assertThat(nextActivity, notNullValue());
     		assertThat(activity(nextActivity).view().
         	withId(R.id.nextActivityContent), hasText("success"));
     }
    
  3. 持续集成和测试你的应用

  4. 让你的应用可以直接上架(With ProGuard to AppStore)

  5. 获得应用的错误等日志反馈

  6. 构建企业应用程序

    企业应用程序有不同的要求,与后端系统的有关部署,安全和通信。它为在Android上构建企业解决方案提供了几个组件:

    交货门户网站:管理用户和交付/更新/管理您的应用程序在空中。

    先进的后端连接:易于与您的后端使用REST,Web服务,JSON或protobuf的沟通。支持几种加密方法,以及使用云服务。 从现场设备的数据同步:保持与后端同步,支持离线模式,合并。

    隐私权存储:提高你的设备上的数据通过加密和您的应用程序的私有数据的安全性。

    使用STAND,你可以轻松地构建基于Android的企业级解决方案。

详细介绍

  1. MAVEN PLUGIN

    网址: http://code.google.com/p/maven-android-plugin

    源代码: GitHub

  2. MAVEN 骨架

    使用方法:

     mvn archetype:generate \
       -DarchetypeArtifactId=android-quickstart \
       -DarchetypeGroupId=de.akquinet.android.archetypes \
       -DarchetypeVersion=1.0.11 \
       -DgroupId=your.company \
       -DartifactId=my-android-application
    

    源代码:Github

  3. ANDROLOG

    Maven依赖

     <dependency>
       <groupId>de.akquinet.android.androlog</groupId>
       <artifactId>androlog</artifactId>
       <version>1.0.1</version>
       <scope>compile</scope>
     </dependency>
    

    使用方法1(跟Android log一样使用,无需配置):

     import de.akquinet.android.androlog.Log;
    
     public class AndrologExample {
         public static final String TAG = "MY_TAG";
         public void doSomething() {
             Log.i(TAG, "A message");
         }
     }
    

    使用方法2:

     import de.akquinet.android.androlog.Log;
     import android.app.Activity;
     import android.os.Bundle;
    
     public class MyActivity extends Activity {
         /** Called when the activity is first created. */
         @Override
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
    
             // Initializes androlog
             // This will read the /sdcard/my.application.properties file
             Log.init(this);
    
             // Log a messgage
             Log.i(this, "This is a logged message");
    
             setContentView(R.layout.main);
         }
     }	
    

    配置:

    文件名是包名+.properties.是不是很简单?

    格式如下:

     androlog.active = true|false
    
     androlog.default.level=VERBOSE|DEBUG|INFO|WARN|ERROR 默认Info
    
     org.package.name = info    //这个格式很眼熟吧?
    
     androlog.delegate.wtf = false  //如果你的系统低于2.3则需要这样设置以免报错
    

    发布前提条件,在~/.m2/settings.xml定义

     <profiles>
       <profile>
         <id>android</id>
        <properties>
          <!-- CHANGE HERE -->
          <sdk.path>/Users/clement/dev/android</sdk.path>
        </properties>
        </profile>
        <!-- others profiles -->
     </profiles>
     <activeProfiles>
         <activeProfile>android</activeProfile>
     </activeProfiles>
    

    源代码:Github

  4. 更好的单元测试工具 - MARVIN

    Maven依赖:

     <dependency>
         <groupId>de.akquinet.android.marvin</groupId>
         <artifactId>marvin</artifactId>
         <version>1.1.0</version>
         <<scope>compile</scope>
     </dependency>
    

    原生的测试方法:

     public class LoginActivityTest extends AndroidTestCase {
         public void testLogin() {
             Instrumentation instrumentation = getInstrumentation();
    
             ActivityMonitor monitor = instrumentation
                 .addMonitor(MainActivity.class.getName(), null, false);
             Intent intent = new Intent(Intent.ACTION_MAIN);
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             intent.setClassName(instrumentation.getTargetContext(),
                 LoginActivity.class.getName());
             final LoginActivity loginActivity= 
                 (LoginActivity) instrumentation.startActivitySync(intent);
             instrumentation.waitForIdleSync();
    
             injectViewTestActivity.runOnUiThread(new Runnable() {
                 public void run() {
                     EditText username = loginActivity
                         .findViewById(R.id.username);
                     EditText password = loginActivity
                         .findViewById(R.id.password);
    
                     username.setText("Username");	// Step 1
                     password.setText("Password");	// Step 2
                     loginActivity.findViewById(R.id.loginbutton)
                         .performClick();	// Step 3
                 }
             });
    
             Activity mainActivity = instrumentation
                 .waitForMonitorWithTimeout(monitor, 30000); // Step 4
             assertNotNull(mainActivity); // Step 5
         }
     }
    

    更好的测试方法(译者:你认为呢?):

     public class LoginActivityTest extends ActivityTestCase<> {
         public LoginActivityTest(Class activityType) {
             super(LoginActivity.class);
         }
    
         public void testLogin() {
             // Step 1
             activity().view().withId(R.id.username).setText("Username");
             // Step 2
             activity().view().withId(R.id.password).setText("Password");
             // Step 3
             activity().view().withId(R.id.loginbutton).click();
             // Step 4
             Activity mainActivity = await().activity(MainActivity.class, 30,
                 TimeUnit.SECONDS);
             assertNotNull(mainActivity); //Step 5
         }
     }
    

    总结:

    使用Marvin,你的测试可以继承以下几个的类:AndroidTestCase, AndroidActivityTestCase, AndroidServiceTestCase.提供以下perform(), await() 和 activity() 或者 view()的交互方法.还支持HAMCREST Matcher, 还有几个全局监控类:

     getMostRecentlyStartedActivity() - 返回最后的已经开启的
    
    
     activitygetStartedActivities() - 返回所有当前正在运行的activity
    
     waitForActivity(Class, long, TimeUnit) - 延时启动特定activity
    

    源代码:Github

  5. 简化开发难度(代码工人的福音)

    简单介绍: 使用roboject必须继承RobojectActivity,包括几个可用的注解

    • @InjectLayout: Injects an XML layout to your activity.

    • @InjectView: Inject an XML view to a field of your activity.

    • @InjectExtra: Inject an Intent extra passed from another activity to a field of your activity.

    • @InjectService: Inject the binder object of a service to a field of your activity.

    And two additional methods:

    • onServicesConnected: Runs in brackground and is called, when all Services were bound. Use this method to process time consuming parts, such as clietn requests to a server.
    • onReady: Is called subsequently to onServicesConnected on the UI-Thread. Manipulate the layout here.

    源代码:Github

最后

All STAND frameworks are available under the Apache License 2.0

##真的是最后 本文来自英文网站

<maven>maven 项目配置 maven 私服,从私服下载 jar

maven 项目配置 maven 私服,从私服下载 jar

首先,保证 public 池里有 自定义 respository

 

然后,保证总的 settings.xml 的 mirrors 中,public 在最上面.

两种方式

1.pom 文件配置私服地址

	<!-- 仓库地址 -->
	<repositories>
		<repository>
			<id>public</id>
			<name>Public Repositories</name>
			<url>http://192.168.3.17/nexus/content/groups/public/</url>
		</repository>
	</repositories>

	<!-- 插件地址 -->
	<pluginRepositories>
		<pluginRepository>
			<id>public</id>
			<name>Public Repositories</name>
			<url>http://192.168.3.17/nexus/content/groups/public/</url>
		</pluginRepository>
	</pluginRepositories>

在构建 maven 项目时,如果在私服中存在需要的构件,则会直接从私服中下载;

如果私服中没有所需构件,则会先从网络上下载到私服,之后才会下载到本地。

2. 全局配置 maven 私服

修改全局的 settings.xml 文件

	<profiles>
		<profile>
			<id>public</id>
			<repositories>
				<repository>
					<id>Public Repositories</id>
					<url>http://192.168.3.17/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>Public Repositories</id>
					<url>http://192.168.3.17/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>


	<activeProfiles>
		<activeProfile>public</activeProfile>
	</activeProfiles>

 

AspectJ 注释在 JAVA maven 项目不是 spring 项目中不起作用 注解必须具有 RUNTIME 范围方面必须有 @Aspect 注释避免双日志输出添加缺少的 Maven 插件执行删除多余的 AspectJ 依赖确保旧的 AspectJ Maven 插件使用最新的 AspectJ 编译器

AspectJ 注释在 JAVA maven 项目不是 spring 项目中不起作用 注解必须具有 RUNTIME 范围方面必须有 @Aspect 注释避免双日志输出添加缺少的 Maven 插件执行删除多余的 AspectJ 依赖确保旧的 AspectJ Maven 插件使用最新的 AspectJ 编译器

如何解决AspectJ 注释在 JAVA maven 项目不是 spring 项目中不起作用 注解必须具有 RUNTIME 范围方面必须有 @Aspect 注释避免双日志输出添加缺少的 Maven 插件执行删除多余的 AspectJ 依赖确保旧的 AspectJ Maven 插件使用最新的 AspectJ 编译器

我正在尝试在没有 spring 的 JAVA maven 项目中实现 AspectJ 注释。我添加了方面并创建了注释。但它没有调用我作为注释添加到方法的方面..下面是我的代码..还有项目链接 - https://github.com/chandru-kumar/aop-example

我也添加了aspectj maven插件..但它没有被调用..你能帮忙..吗?不知道我错过了什么。 我没有找到任何没有 Spring 项目的例子..

Pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.aop.example</groupId>
  4. <artifactId>aop-example</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. <properties>
  7. <java.version>1.8</java.version>
  8. </properties>
  9. <dependencies>
  10. <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
  11. <dependency>
  12. <groupId>org.aspectj</groupId>
  13. <artifactId>aspectjweaver</artifactId>
  14. <version>1.9.6</version>
  15. </dependency>
  16. <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
  17. <dependency>
  18. <groupId>org.aspectj</groupId>
  19. <artifactId>aspectjtools</artifactId>
  20. <version>1.9.6</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.aspectj</groupId>
  24. <artifactId>aspectjrt</artifactId>
  25. <version>1.9.6</version>
  26. </dependency>
  27. </dependencies>
  28. <build>
  29. <plugins>
  30. <plugin>
  31. <groupId>org.codehaus.mojo</groupId>
  32. <artifactId>aspectj-maven-plugin</artifactId>
  33. <version>1.11</version>
  34. <configuration>
  35. <complianceLevel>1.8</complianceLevel>
  36. <source>1.8</source>
  37. <target>1.8</target>
  38. </configuration>
  39. </plugin>
  40. <plugin>
  41. <groupId>org.apache.maven.plugins</groupId>
  42. <artifactId>maven-surefire-plugin</artifactId>
  43. <version>2.22.0</version>
  44. </plugin>
  45. <plugin>
  46. <groupId>org.apache.maven.plugins</groupId>
  47. <artifactId>maven-compiler-plugin</artifactId>
  48. <version>3.1</version>
  49. <configuration>
  50. <source>1.8</source>
  51. <target>1.8</target>
  52. <useIncrementalCompilation>false</useIncrementalCompilation>
  53. </configuration>
  54. </plugin>
  55. <!-- <plugin>
  56. <groupId>org.codehaus.mojo</groupId>
  57. <artifactId>aspectj-maven-plugin</artifactId>
  58. <executions>
  59. <execution>
  60. <goals>
  61. <goal>compile</goal>
  62. </goals>
  63. <configuration>
  64. <complianceLevel>1.8</complianceLevel>
  65. <source>1.8</source>
  66. <target>1.8</target>
  67. </configuration>
  68. </execution>
  69. </executions>
  70. </plugin> -->
  71. <plugin>
  72. <groupId>org.apache.maven.plugins</groupId>
  73. <artifactId>maven-assembly-plugin</artifactId>
  74. <executions>
  75. <execution>
  76. <phase>package</phase>
  77. <goals>
  78. <goal>single</goal>
  79. </goals>
  80. <configuration>
  81. <archive>
  82. <manifest>
  83. <mainClass>
  84. com.aop.example.Test
  85. </mainClass>
  86. </manifest>
  87. </archive>
  88. <descriptorRefs>
  89. <descriptorRef>jar-with-dependencies</descriptorRef>
  90. </descriptorRefs>
  91. </configuration>
  92. </execution>
  93. </executions>
  94. </plugin>
  95. </plugins>
  96. </build>
  97. </project>

JAVA - 方面 - 建议

  1. package com.aop.advices;
  2. import org.aspectj.lang.ProceedingJoinPoint;
  3. import org.aspectj.lang.annotation.Around;
  4. public class SysoutAdvice {
  5. @Around("@annotation(com.annotations.Sysout)")
  6. public Object print(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
  7. System.out.println("Start....");
  8. Object object = proceedingJoinPoint.proceed();
  9. System.out.println("End....");
  10. return object;
  11. }
  12. }

JAVA - 注释

  1. import static java.lang.annotation.ElementType.METHOD;
  2. import static java.lang.annotation.RetentionPolicy.RUNTIME;
  3. import java.lang.annotation.Retention;
  4. import java.lang.annotation.Target;
  5. @retention(RUNTIME)
  6. @target(METHOD)
  7. public @interface Sysout{}

解决方法

我可以看出您是 AspectJ 初学者。你犯了很多错误。不过别担心,随着时间的推移,您会学习并获得更多经验。

注解必须具有 RUNTIME 范围

否则编译后的代码不会有注释拦截,只有源代码,无济于事。

方面必须有 @Aspect 注释

否则 AspectJ 编译器不会将该类识别为方面。

避免双日志输出

如果不添加 && execution(* *(..)),切面将同时拦截 callexecution 连接点。效果将是双日志消息,因为方面建议被触发两次。

添加缺少的 Maven 插件执行

否则 AspectJ Maven 插件不会编译任何东西,因为您没有告诉它要做什么。

删除多余的 AspectJ 依赖

否则,Assembly 插件会将它们打包到可执行 JAR 中,将其压缩到 13.4 MB。但实际上,当使用编译时编织时,您只需要 AspectJ 运行时 aspectjrt 即可运行应用程序。其他两个用于加载时编织 (aspectjweaver) 和 AspectJ 编译器 (aspetjtools),您在运行时不需要这两者。

如果您按照我的建议删除这两个,JAR 大小会急剧缩小到 0.12 MB。这小了 100 多倍。

确保旧的 AspectJ Maven 插件使用最新的 AspectJ 编译器

版本号应与用于 aspectjrt 的版本号相同。所以你不需要 aspetjtools 作为运行时依赖,而是作为插件依赖,如果你想确保你有相同的版本。

这一步是可选的,但 AspectJ Maven 1.11 默认使用 AspectJ Tools 1.8.13。如果你只是编译 Java 8 代码,这很好,因为 AspectJ Maven 1.11 不支持超过 Java 8。

如果您想要一个支持 AspectJ 1.9.7.M3 和 Java 16 的更现代的插件,请查看 dev.aspectj plugin version(请注意其他 Maven 组 ID!)。

在您的 Maven 配置中应该更改其他次优的东西,但这是最重要的东西,它使您的项目运行并且您的可执行 JAR 变小。


更新:这是我的 pull request,它修复了上述问题以及其他一些问题(请参阅提交评论)。

eclipse maven build、maven clean、maven install和maven test的区别 精析

eclipse maven build、maven clean、maven install和maven test的区别 精析

 
 
 

1.情景展示

  选中maven项目,右键-->Run As或Debug As-->maven buid,maven install,maven test有什么区别?

2.区别说明

  6 Maven  clean-->执行的是maven的原生命令:

mvn clean

  表示:删除target目录。

  原目录结构存在target目录

  执行该命令后, target目录被删除。

  2018/11/14

  选中target目录-->右键-->刷新-->在windows资源管理器下打开该目录,你会发现class已经重新编译好

  注意:这不是mvn clean命令执行的只是清空target目录,classes文件之所以重新被编译,依赖于eclipse的自动编译功能!  

  7 Maven generate-sources-->执行的是maven的原生命令:

mvn generate-sources

  表示:会根据pom配置去生成源代码格式的包,产生应用需要的任何额外的源代码(没用过)

  8 Maven  install-->执行的是maven的原生命令:

mvn install

  表示:对项目进行编译、将项目打成war包并且发布到本地仓库。

  target目录说明:

  classes目录:.class,.properties,.xml文件;

  项目名目录:项目所有源码(前端、后台、jar包)

  项目名.war:将项目名目录打成的war包。

  生成的target目录展示

  安装到本地仓库的目录展示

  9 Maven  test-->执行的是maven的原生命令:

mvn test

  表示的是:对项目进行编译并执行测试代码。  

  生成的目录:

  5 Maven build...-->maven没有mvn buid命令 

  表示的是:这是eclipse自带的mvn插件,通过这个功能,你可以自定义设置要执行的maven命令。

  用这个功能,我们能干什么?

  举2个栗子:

  案例一:

  因为maven在打包时,如果已经存在一个包时,再次执行打包命令时,如果不把原来的war包删除,经常会导致包没有更新;

  这时,我们就需要先清除该war包(执行clean命令对应eclipse中的Maven clean功能),再重新打包(执行package或install命令对应eclipse中的Maven install功能)。

  我们可以使用"Maven build"这个功能,在"Goals"一栏,输入命令:clean install,执行一次即可。

  案例二:

  对项目进行打包的时候,跳过单元测试。

  eclipse没有这个功能,只能通过自定义maven命令来实现,在Maven build...这个功能进行设置。

  示例一:打包并发布到本地仓库

  错误用法:不设置命令,直接run

  相当于maven命令:

mvn

  报错信息如下: 

  正确用法:输入 install

 

  示例二:打包时,跳过单元测试

  方式一:在上图勾选上“Skip Tests”

  使用这种方式:src/test/java和src/test/resources这两个目录下的文件不会被编译,自然不会被添加到编译好的项目当中。

  方式二:声明maven命令:“-DskipTests”

  使用这种方式: src/test/java和src/test/resources这两个目录下的文件依然会被编译,但不会被添加到编译好的项目当中。

  4 Maven build

  表示的是:执行已经定义好的maven命令。

  一个项目可以“Maven build...”功能定义n个maven命令,然后通过“Maven build”功能来执行想要执行的命令。

  Run Configurations...

  可通过这个功能,对已经自定义的maven命令进行新建、修改、运行、删除;

  如何删除多余的maven命令?

  选中不需要的maven命令,右键-->“删除”即可。

3.maven其它命令说明

mvn compile

  表示的是:对项目源代码进行编译。  

生成的目录:

mvn deploy

  表示的是:将项目发布到远程仓库。

mvn dependency:tree

  表示的是:显示maven依赖树。

mvn dependency:list

  表示的是:显示maven依赖列表。

mvn package

  表示的是:编译项目并打成war包。

  跳过单元测试的两种方式:

  方式一:

-DskipTests

  方式二:

-Dmaven.test.skip=true

  表示的是:测试类不会被编译,或即使被编译也不会被添加到项目当中。

  另外,这个指令没有先后顺序,均能正常执行。  

  举例: 以打包并发布到本地仓库时,跳过测试类为例。

// 方式一:形式一
mvn install -DskipTests
// 方式一:形式二
mvn -DskipTests install
// 方式二:形式一
mvn install -Dmaven.test.skip=true
// 方式二:形式二
mvn -Dmaven.test.skip=true install

 

写在最后

  哪位大佬如若发现文章存在纰漏之处或需要补充更多内容,欢迎留言!!!

 相关推荐:

  • maven 配置环境变量

 

 

Eclipse 使用 Maven 创建 Web 时错误:Could not resolve archetype org.apache.maven.archetypes:maven-ar

Eclipse 使用 Maven 创建 Web 时错误:Could not resolve archetype org.apache.maven.archetypes:maven-ar

Eclipse 使用 Maven 创建 Web 时错误:Could not resolve archetype org.apache.maven.archetypes:maven-ar

喜欢本站的朋友可以收藏本站,或者加入 QQ 群:172816590, 我们大家一起来交流技术!

欢迎来到梁钟霖个人博客网站。本个人博客网站提供最新的站长新闻,各种互联网资讯。 还提供个人博客模板,最新最全的 java 教程,java 面试题。在此我将尽我最大所能将此个人博客网站做的最好!谢谢大家,愿大家一起进步! 

使用 Eclipse 自带的 Maven 插件创建 Web 项目时报错:

Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE
Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in local (C:\Users\liujunguang\.m2\repository)
Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in local (C:\Users\liujunguang\.m2\repository)

解决方案:

1. 在 Eclipse Maven 配置中添加新的 Catalog 配置:

  • http://repo1.maven.org/maven2/archetype-catalog.xml

如图:

接下来在使用刚添加的 catalog 创建 web 工程

这个时候就可以看到 Eclipse 联网下载了:

如果还是不能创建或者问题没有解决可以安装下面的方法:

1. 删除 maven 已经下载的文件路径:.m2\repository\org\apache\maven

删除之后再试下,这时候如果看到有进度,只需要耐心等待就行了


2.Maven 下载 jar 慢可以使用国内阿里镜像

具体配置文件(settings.xml)如下,放在.m2 文件夹下,.m2 一般位于用户目录下
 

<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
            http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
    <!-- 这个是配置阿里 Maven 镜像 -->
    <mirrors>
        <mirror>
          <id>aliyun</id>
          <name>aliyun</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
    
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://repo.maven.apache.org/maven2</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>ansj-repo</id>
                    <name>ansj Repository</name>
                    <url>http://maven.nlpcn.org/</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>
 
    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
</settings>

如果此时还不成功,可以查看下当前 maven 创建 webapp 的 jar 包是否存在,找到自己的 response,我的目录是在

C:\Users\windowsusr\.m2\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.3 下

文件夹里发现下载 jar 包失败,解决方案如下:

去 maven 仓库下载:https://mvnrepository.com/search?q=maven-archetype-webapp-1.3,如下图

点击 view 进去后下载必要的文件到本地私有仓库里

然后重新创建一遍 maven springmvc 项目后,成功!!


 转载至链接:https://my.oschina.net/u/193508/blog/2872838。

今天关于高效建立健壮的Android应用-Maven Android 开发的分享就到这里,希望大家有所收获,若想了解更多关于maven 项目配置 maven 私服,从私服下载 jar、AspectJ 注释在 JAVA maven 项目不是 spring 项目中不起作用 注解必须具有 RUNTIME 范围方面必须有 @Aspect 注释避免双日志输出添加缺少的 Maven 插件执行删除多余的 AspectJ 依赖确保旧的 AspectJ Maven 插件使用最新的 AspectJ 编译器、eclipse maven build、maven clean、maven install和maven test的区别 精析、Eclipse 使用 Maven 创建 Web 时错误:Could not resolve archetype org.apache.maven.archetypes:maven-ar等相关知识,可以在本站进行查询。

本文标签: