V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
baiyekaslana
V2EX  ›  Java

windows 使用 IDEA,通过 maven 打包一个开源项目的求助

  •  
  •   baiyekaslana · 80 天前 · 1782 次点击
    这是一个创建于 80 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://github.com/devlive-community/datacap.git 本地打算源码打包安装 datacap 项目,但是现在 jdk 使用 1.8 版本的话,后面打包就会提示 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (java-compile) on project datacap-captcha: Fatal error compiling: 无效的目标发行版: 11 -> [Help 1] 让你使用 jdk11. 要是使用 jdk11 的话,开始就会提示无法找到 tools.jar,要用 tools.jar 就得换回 jdk1.8 我想知道这个开源项目源码到底要怎么打包。

    31 条回复    2024-09-30 15:44:27 +08:00
    a33291
        1
    a33291  
       80 天前
    jvav 这么无敌的兼容性,编译用 11,然后把 8 的 tools.jar 放到 11 的 classpath 不就好了
    baiyekaslana
        2
    baiyekaslana  
    OP
       80 天前
    @a33291 试过了,还是提示没有 tools.jar
    zypy333
        3
    zypy333  
       80 天前
    无效的目标发行版: 11 是你的项目里有些配置不对吧,到 compiler 跟 module 选项里检查下
    sagaxu
        4
    sagaxu  
       80 天前
    不要用 IDEA ,直接在命令行下面打包
    ikas
        5
    ikas  
       80 天前
    这个项目需要 jdk11 以上
    你的 idea 是不是版本太低,里面内置的 maven 版本太低,还是指定了较低版本的 maven?

    项目 sdk 设置为 jdk11+
    然后 idea 设置中将 maven 指定为 3.7+,另外 maven runner 设置使用项目 jdk

    已经测试 idea2024.2 jdk21 正常编译
    1462326016
        6
    1462326016  
       80 天前
    @ikas #5 +1 实测 jdk11 正常编译,版本号如下
    -Didea.version=2024.2.2
    openjdk@11/11.0.24
    apache-maven-3.6.3
    Belmode
        7
    Belmode  
       80 天前
    https://imgur.com/Lpd93n5
    这是 OP 问的吧,对方已经修复了这个问题,不过编译还是至少使用 JDK11+

    相关文档: https://datacap.devlive.org/developer/server/home.html

    我简单看了一下,这个项目挺不错的,就是不知道稳定性怎么样。
    baiyekaslana
        8
    baiyekaslana  
    OP
       78 天前
    @ikas 提示找不到 tools.jar,好像是引用的时候有个..到上一级目录,是 jdk-11/../lib/tools.jar,然后把 lib 复制到外面之后就不报这个错了,我用的 jdk11,和 maven3.6.3 版本,现在是 clean 正常,但是 package 的时候又报错了,idea 是 2023.3.6 版本
    baiyekaslana
        9
    baiyekaslana  
    OP
       78 天前
    @ikas ./mvnw -T 1C clean install package -Dspotbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true
    在那个官网上,说要使用命令行执行这个,但是我用 idea 就提示识别不了.skip ,用的 windows10 ,要加这些参数再 idea 上能加嘛,还是只能去 pom 文件里加
    ikas
        10
    ikas  
       78 天前
    这些参数只是跳过一些执行操作.

    如果你非要在 idea 中操作,那么
    我建议先不用 mvnw,而是在设置中将 maven 指定为自己下载的

    > idea 设置中将 maven 指定为 3.7+,另外 maven runner 设置使用项目 jdk

    这些参数可以在 idea 的 maven 边栏的工具栏中,有个执行命令的按钮,点击输入 package -Dspotbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true 即可
    baiyekaslana
        11
    baiyekaslana  
    OP
       78 天前
    @ikas 没想非要执行这些操作,就是现在 maven 这些都配置了,jdk 也配置了,然后编译和 maven 的操作都有报错
    baiyekaslana
        12
    baiyekaslana  
    OP
       78 天前
    @ikas 构建的时候还有个 gpg 认证的吧,这个不跳过不行吧?
    ikas
        13
    ikas  
       78 天前
    一般都是习惯配置好 maven path,直接 mvn compile,有啥错就看看,该跳肯定跳.....
    主要是 idea 对 maven 项目导入太慢
    baiyekaslana
        14
    baiyekaslana  
    OP
       78 天前
    @ikas 除啦这个 maven 配置和 jdk 配置还需要啥操作嘛,我 idea 换成 24.2.2 也还是不行
    ikas
        15
    ikas  
       78 天前   ❤️ 1
    是不是你的网络有问题,这个项目还有前端项目(datacap-server datacap-ui)需要编译的,会自动下载 node 等,如果没法访问 github 是不行的

    mvn compile -U -Dspotbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true


    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary for datacap 2024.3.10-SNAPSHOT:
    [INFO]
    [INFO] datacap ............................................ SUCCESS [ 21.434 s]
    [INFO] datacap-captcha .................................... SUCCESS [ 0.292 s]
    [INFO] datacap-fs-spi ..................................... SUCCESS [ 0.062 s]
    [INFO] datacap-scheduler-spi .............................. SUCCESS [ 5.759 s]
    [INFO] datacap-common ..................................... SUCCESS [ 4.450 s]
    [INFO] datacap-client-cli ................................. SUCCESS [ 3.201 s]
    [INFO] datacap-parser ..................................... SUCCESS [ 0.127 s]
    [INFO] datacap-shaded-pinot ............................... SUCCESS [ 1.962 s]
    [INFO] datacap-convert-spi ................................ SUCCESS [ 1.012 s]
    [INFO] datacap-convert-txt ................................ SUCCESS [ 1.500 s]
    [INFO] datacap-convert-json ............................... SUCCESS [ 1.101 s]
    [INFO] datacap-convert-none ............................... SUCCESS [ 0.690 s]
    [INFO] datacap-convert-csv ................................ SUCCESS [ 0.695 s]
    [INFO] datacap-convert-xml ................................ SUCCESS [ 0.709 s]
    [INFO] datacap-spi ........................................ SUCCESS [ 4.657 s]
    [INFO] datacap-sql ........................................ SUCCESS [ 1.532 s]
    [INFO] datacap-schedule ................................... SUCCESS [ 2.160 s]
    [INFO] datacap-parser-spi ................................. SUCCESS [ 0.562 s]
    [INFO] datacap-parser-trino ............................... SUCCESS [ 8.260 s]
    [INFO] datacap-parser-mysql ............................... SUCCESS [ 16.018 s]
    [INFO] datacap-scheduler-local ............................ SUCCESS [ 0.412 s]
    [INFO] datacap-executor-spi ............................... SUCCESS [ 0.713 s]
    [INFO] datacap-executor-local ............................. SUCCESS [ 0.435 s]
    [INFO] datacap-logger ..................................... SUCCESS [ 2.013 s]
    [INFO] datacap-shell ...................................... SUCCESS [ 2.330 s]
    [INFO] datacap-executor-seatunnel ......................... SUCCESS [ 2.500 s]
    [INFO] datacap-service .................................... SUCCESS [ 6.519 s]
    [INFO] datacap-security ................................... SUCCESS [ 3.060 s]
    [INFO] datacap-jdbc-mysql ................................. SUCCESS [ 2.226 s]
    [INFO] datacap-jdbc-clickhouse ............................ SUCCESS [ 2.236 s]
    [INFO] datacap-jdbc-presto ................................ SUCCESS [ 2.184 s]
    [INFO] datacap-driver-redis ............................... SUCCESS [ 0.048 s]
    [INFO] datacap-jdbc-redis ................................. SUCCESS [ 2.249 s]
    [INFO] datacap-jdbc-trino ................................. SUCCESS [ 2.567 s]
    [INFO] datacap-jdbc-postgresql ............................ SUCCESS [ 2.266 s]
    [INFO] datacap-jdbc-elasticsearch ......................... SUCCESS [ 2.277 s]
    [INFO] datacap-jdbc-druid ................................. SUCCESS [ 2.245 s]
    [INFO] datacap-jdbc-kyuubi ................................ SUCCESS [ 2.232 s]
    [INFO] datacap-jdbc-hive .................................. SUCCESS [ 4.242 s]
    [INFO] datacap-jdbc-kylin ................................. SUCCESS [ 2.198 s]
    [INFO] datacap-jdbc-ignite ................................ SUCCESS [ 2.187 s]
    [INFO] datacap-jdbc-db2 ................................... SUCCESS [ 2.354 s]
    [INFO] datacap-jdbc-dremio ................................ SUCCESS [ 2.227 s]
    [INFO] datacap-jdbc-monetdb ............................... SUCCESS [ 2.136 s]
    [INFO] datacap-jdbc-phoenix ............................... SUCCESS [ 6.836 s]
    [INFO] datacap-jdbc-h2 .................................... SUCCESS [ 2.117 s]
    [INFO] datacap-jdbc-sqlserver ............................. SUCCESS [ 2.139 s]
    [INFO] datacap-jdbc-oracle ................................ SUCCESS [ 2.174 s]
    [INFO] datacap-jdbc-cratedb ............................... SUCCESS [ 2.256 s]
    [INFO] datacap-jdbc-dm .................................... SUCCESS [ 2.117 s]
    [INFO] datacap-http-cratedb ............................... SUCCESS [ 2.243 s]
    [INFO] datacap-http-clickhouse ............................ SUCCESS [ 2.122 s]
    [INFO] datacap-jdbc-tdengine .............................. SUCCESS [ 2.241 s]
    [INFO] datacap-jdbc-impala ................................ SUCCESS [ 2.278 s]
    [INFO] datacap-jdbc-oceanbase ............................. SUCCESS [ 2.120 s]
    [INFO] datacap-native-redis ............................... SUCCESS [ 2.157 s]
    [INFO] datacap-jdbc-neo4j ................................. SUCCESS [ 2.175 s]
    [INFO] datacap-jdbc-iotdb ................................. SUCCESS [ 2.360 s]
    [INFO] datacap-jdbc-snowflake ............................. SUCCESS [ 2.187 s]
    [INFO] datacap-shaded-ydb ................................. SUCCESS [ 1.255 s]
    [INFO] datacap-jdbc-ydb ................................... SUCCESS [ 2.128 s]
    [INFO] datacap-native-zookeeper ........................... SUCCESS [ 2.257 s]
    [INFO] datacap-jdbc-duckdb ................................ SUCCESS [ 2.111 s]
    [INFO] datacap-native-alioss .............................. SUCCESS [ 2.343 s]
    [INFO] datacap-native-kafka ............................... SUCCESS [ 2.204 s]
    [INFO] datacap-native-h2 .................................. SUCCESS [ 2.229 s]
    [INFO] datacap-http-ceresdb ............................... SUCCESS [ 2.282 s]
    [INFO] datacap-http-greptime .............................. SUCCESS [ 2.315 s]
    [INFO] datacap-http-questdb ............................... SUCCESS [ 2.283 s]
    [INFO] datacap-jdbc-doris ................................. SUCCESS [ 0.357 s]
    [INFO] datacap-jdbc-starrocks ............................. SUCCESS [ 0.299 s]
    [INFO] datacap-jdbc-hologres .............................. SUCCESS [ 0.312 s]
    [INFO] datacap-native-hdfs ................................ SUCCESS [ 0.678 s]
    [INFO] datacap-plugin-pinot ............................... SUCCESS [ 0.441 s]
    [INFO] datacap-driver-mongo ............................... SUCCESS [ 0.019 s]
    [INFO] datacap-plugin-mongo-community ..................... SUCCESS [ 0.318 s]
    [INFO] datacap-plugin-cassandra ........................... SUCCESS [ 0.652 s]
    [INFO] datacap-plugin-matrixone ........................... SUCCESS [ 0.288 s]
    [INFO] datacap-plugin-scylladb ............................ SUCCESS [ 0.434 s]
    [INFO] datacap-plugin-paradedb ............................ SUCCESS [ 0.249 s]
    [INFO] datacap-plugin-timescale ........................... SUCCESS [ 0.245 s]
    [INFO] datacap-plugin-solr ................................ SUCCESS [ 0.262 s]
    [INFO] datacap-plugin-influxdb ............................ SUCCESS [ 0.244 s]
    [INFO] datacap-fs-local ................................... SUCCESS [ 2.098 s]
    [INFO] datacap-fs-qiniu ................................... SUCCESS [ 0.466 s]
    [INFO] datacap-fs-alioss .................................. SUCCESS [ 0.429 s]
    [INFO] datacap-fs-tencent-cos ............................. SUCCESS [ 0.392 s]
    [INFO] datacap-fs-amazon-s3 ............................... SUCCESS [ 0.405 s]
    [INFO] datacap-fs-minio ................................... SUCCESS [ 0.458 s]
    [INFO] datacap-notify-spi ................................. SUCCESS [ 0.265 s]
    [INFO] datacap-http ....................................... SUCCESS [ 2.213 s]
    [INFO] datacap-notify-dingtalk ............................ SUCCESS [ 0.314 s]
    [INFO] datacap-server ..................................... SUCCESS [01:35 min]
    [INFO] datacap-jdbc-mongo ................................. SUCCESS [ 8.526 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 05:07 min
    [INFO] Finished at: 2024-09-29T22:14:54+08:00
    [INFO] ------------------------------------------------------------------------
    ikas
        16
    ikas  
       78 天前
    我的环境是就是 idea 24.2, Maven 3.8.5, Jdk 21 ,maven 使用腾讯云的镜像
    baiyekaslana
        17
    baiyekaslana  
    OP
       78 天前
    @ikas [ERROR] Unknown lifecycle phase ".skip". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, init
    ialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
    我加参数就会提示这个
    baiyekaslana
        18
    baiyekaslana  
    OP
       78 天前
    @baiyekaslana
    @ikas 这个错误找到了,windows 的 power shell 终端执行这个命令需要在每个参数两边加单引号
    mvn compile -U '-Dspotbugs.skip' '-Dgpg.skip' '-Dcheckstyle.skip' -DskipTests=true
    我执行这样就行了
    baiyekaslana
        19
    baiyekaslana  
    OP
       78 天前
    之前问 gpt 也没提示
    baiyekaslana
        20
    baiyekaslana  
    OP
       78 天前
    @ikas [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.0:yarn (yarn install) on project datacap-server: Failed to run task: 'yarn --legacy-peer-deps install' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
    本地已经下载 yarn ,path 里也加了,但是还是报这个错误
    ikas
        21
    ikas  
       77 天前
    这个实际是 yarn --legacy-peer-deps install 执行失败了, 应该是前端项目的依赖无法下载把
    手动到 datacap-ui 模块执行 yarn --legacy-peer-deps install 试试
    baiyekaslana
        22
    baiyekaslana  
    OP
       77 天前
    @ikas 这个是当时执行的。
    [INFO] datacap-notify-dingtalk ............................ SUCCESS [ 0.269 s]
    [INFO] datacap-server ..................................... FAILURE [02:27 min]
    [INFO] datacap-jdbc-mongo ................................. SKIPPED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 03:51 min
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.0:yarn (yarn install) on project datacap-server: Failed to run task: 'yarn --legacy-peer-deps install' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [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]
    [ERROR] After correcting the problems, you can resume the build with the command
    [ERROR] mvn <args> -rf :datacap-server
    baiyekaslana
        23
    baiyekaslana  
    OP
       77 天前
    @ikas 应该是 datacap-server 的模块无法下载,datacap-ui 的我还没拉。
    baiyekaslana
        24
    baiyekaslana  
    OP
       77 天前
    @ikas 您说的这个手动到模块下执行 yarn --legacy-peer-deps install ,是说的 maven 那个对应的模块里输入这个命令嘛?
    baiyekaslana
        25
    baiyekaslana  
    OP
       77 天前
    @baiyekaslana
    @ikas 我搜了下,是在对应的模块目录下的终端执行是吗
    ikas
        26
    ikas  
       77 天前
    打开目录 datacap\core\datacap-ui
    然后使用在该目录,使用 cmd 执行 yarn --legacy-peer-deps install

    这个已经不是 java 与 maven 了,而是前端编译
    baiyekaslana
        27
    baiyekaslana  
    OP
       77 天前
    @ikas 我看文件里自带 package-lock.json ,这个是 npm 使用的锁文件吧,程序用 yarn 不会相互影响嘛
    baiyekaslana
        28
    baiyekaslana  
    OP
       77 天前
    @ikas

    PS C:\Users\baiye\Desktop\datacap_dev\datacap\core\datacap-ui> yarn --legacy-peer-deps install
    yarn install v1.22.22
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    Done in 153.99s.
    PS C:\Users\baiye\Desktop\datacap_dev\datacap\core\datacap-ui>
    ikas
        29
    ikas  
       77 天前
    前端依赖下载好了.回到 maven 去编译把
    baiyekaslana
        30
    baiyekaslana  
    OP
       77 天前
    @ikas
    现在好了,为啥需要手动编译前端文件才行,他自己那个命令就会报错?
    [INFO] datacap-notify-spi ................................. SUCCESS [ 0.231 s]
    [INFO] datacap-http ....................................... SUCCESS [ 0.620 s]
    [INFO] datacap-notify-dingtalk ............................ SUCCESS [ 0.314 s]
    [INFO] datacap-server ..................................... SUCCESS [01:11 min]
    [INFO] datacap-jdbc-mongo ................................. SUCCESS [ 0.628 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 02:42 min
    [INFO] Finished at: 2024-09-30T14:52:42+08:00
    [INFO] ------------------------------------------------------------------------
    PS C:\Users\baiye\Desktop\datacap_dev\datacap>
    ikas
        31
    ikas  
       77 天前
    主要是国内网络限制...

    你手动执行,也有提示
    [2/4] Fetching packages...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...


    你用 maven 多执行几次,可能也会成功,但是那样太慢了...所以手动执行,先把依赖(datacap-ui\node_modules)下载下来...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5406 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:06 · PVG 14:06 · LAX 22:06 · JFK 01:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.