关注各种黑科技
B站UP主,编程教学,游戏玩家,挂B,金牛座

Java入坑day02 maven项目开发编译说明

maven pom.xml 依赖找不到 可以本地安装

        <dependency>
            <groupId>com.homewaimai.platform</groupId>
            <artifactId>toolkit.alipay</artifactId>
            <version>0.0.2-SNAPSHOT</version>
        </dependency>

安装本地包

mvn install:install-file -Dfile=toolkit.alipay-0.0.2-SNAPSHOT.jar  -DgroupId=com.homewaimai.platform -DartifactId=toolkit.alipay -Dversion=0.0.2-SNAPSHOT -Dpackaging=jar

groupId artifactId version照抄就行 version在xml里可以省略,默认0.0.1

当然有私服还是丢到私服里统一管理

maven 的配置文件在.m2/settings.xml

localRepository是本地缓存目录,记得用绝对路径就可以

<?xml version="1.0"?>

<settings>
    <localRepository>/Users/n37r06u3/Projects/mvnrepository</localRepository>

    <pluginGroups>
            <pluginGroup>com.xxx.maven.plugins.android.generation2</pluginGroup>
    </pluginGroups>

    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://127.0.0.1:8081/nexus/content/groups/public</url>
        </mirror>
    </mirrors>


    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>nexus</name>
                    <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                    </releases>     
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>nexus</name>
                    <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                </pluginRepository>
            </pluginRepositories>
        </profile>

    </profiles>

<servers>
  <server>
    <id>deployment</id>
    <username>root</username>
    <password>root</password>
  </server>
</servers>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
</settings>

用eclipse开发项目,迁移到idea并不复杂,稍微熟悉就行

file=》 project structure 可以看到项目配置

java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

java home
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

ls -la /usr/bin |grep java
lrwxr-xr-x    1 root   wheel        74 Nov 20  2017 java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
lrwxr-xr-x    1 root   wheel        75 Nov 20  2017 javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
lrwxr-xr-x    1 root   wheel        77 Nov 20  2017 javadoc -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javadoc
lrwxr-xr-x    1 root   wheel        75 Nov 20  2017 javah -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javah
lrwxr-xr-x    1 root   wheel        75 Nov 20  2017 javap -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javap
lrwxr-xr-x    1 root   wheel        82 Nov 20  2017 javapackager -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javapackager
lrwxr-xr-x    1 root   wheel        76 Nov 20  2017 javaws -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javaws

上面的java是用官方的pkg包安装的,可以安装多个版本 比如最新的java11
当前版本由java_home工具指定 切换java8用下面的命令

/usr/libexec/java_home -v 1.8
nano ~/.bash_profile
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"

macos还有个单独的jre, 苹果单独维护, 跑一些内置app用的

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

解决完依赖
下面遇到 properties错误
@Value("${dingding.msg_service_url}")

xxx/src/test/resources/config/xxx.properties

注入错误
No matching bean of type [com.xxxsoft.portal.util.AsyncTaskExecutor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

bean/spring-mvc-context.xml 配置

java nested exception 很恶心,看错误先看最里层的,没有python的详细

即使能编译过,线上跑还是缺少依赖
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [redis.clients.jedis.JedisPoolConfig] for bean with name 'jedisPoolConfig' defined in class path resource [cache/biz-cache.xml]; nested exception is java.lang.ClassNotFoundException: redis.clients.jedis.JedisPoolConfig

java的编译步骤虽然麻烦,但是一套流程还是比较规范的,比python严格,所以说企业级开发还是java的天下

参考

https://blog.csdn.net/u012898245/article/details/79210635
https://blog.csdn.net/u010832551/article/details/73826914
https://blog.csdn.net/hi_boy_/article/details/78541580
https://blog.csdn.net/ryelqy/article/details/77453713
https://stackoverflow.com/questions/8961275/no-matching-bean-of-type-found-for-dependency

https://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-os-x
https://medium.com/@danielnenkov/multiple-jdk-versions-on-mac-os-x-with-jenv-5ea5522ddc9b

转载请注明出处
分享到: 更多 (0)

评论 0