[英]Maven: No sources to compile
我正在关注“使用 Maven 构建 Java 项目”( https://spring.io/guides/gs/maven/#scratch ),当我从 /Users/Misha/Desktop/src/main/java 运行“mvn compile”时/你好,我收到这个提示:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-maven 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gs-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gs-maven ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.942 s
[INFO] Finished at: 2015-01-11T23:10:28-08:00
[INFO] Final Memory: 7M/155M
[INFO] ------------------------------------------------------------------------
我在 hello 目录中有两个 java 文件和一个 xml 文件,我假设我应该看到“Hello World”。 而不是没有编译源? 为什么我的 java 代码没有编译? 谢谢!
要创建您需要的 Maven 项目
pom.xml
文件的项目目录src/main/java
(包转到src/main/java
子目录) 要从项目目录中调用 maven run mvn compile
或类似的东西。
就我而言,我错过了这个:
<project>
...
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
...
</project>
通常,我只会使用默认的目录结构
src/main/java
作为source folder
。src/test/java
作为test folder
。但是我正在使用现有代码处理一个类项目,并且无法重新排列文件结构。
因为$PROJECT_DIR/src/main/java
中没有 java 文件
您是否尝试编译项目或类? 作为https://spring.io/guides/gs/maven/#scratch 中的指南,您需要为项目编译。 尝试从项目方向运行mvn compile
。
就我而言,我不得不将 JDK 版本从 JDK 18 降级到 JDK 17(IDE:Apache NetBeans 15)
我正在向多模块 Kotlin 项目添加一些 Java 代码,在顶层pom.xml
中定义了以下内容:
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
因此,在我将 Java 目录添加到构建配置之前,Maven 从未检测到 Java 代码:
<build>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
...
推荐的 git 工具是:NONE using credential fcdbaabd-0a76-4111-876f-f6c6a5dfb89a
/usr/bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/test3/.git # timeout=10 从远程 Git 存储库获取更改 /usr/bin/git config remote.origin .url https://github.com/Ranjithchary/realme-stand.git # timeout=10 从https://github.com/Ranjithchary/realme-stand.git /usr/bin/git --version 获取上游更改 # timeout=10 git --version # 'git version 2.37.1' 使用 GIT_ASKPASS 设置凭据 /usr/bin/git fetch --tags --force --progress -- https://github.com/Ranjithchary/realme- stand.git +refs/heads/ :refs/remotes/origin/ # timeout=10 /usr/bin/git rev-parse refs/remotes/origin/main^{commit} # timeout=10 检查修订 a37696f887a202dc75b5e7860709b5fff3467998 (refs/ remotes/origin/main) /usr/bin/git config core.sparsecheckout # timeout=10 /usr/bin/git checkout -f a37696f887a202dc75b5e7860709b5fff3467998 # timeout=10 提交消息:“已添加文件” /usr/bin/git rev-list --no-walk a37696f887a202dc75b5e7860709b5fff3467998 # timeout=10 [test3] $ mvn mvn安装错误:JAVA_HOME 未正确定义。 我们无法执行 /opt/openjdk-11.0.2_linux-x64/bin/java Build step 'Invoke top-level Maven targets' marked build as failure Finished: FAILURE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.