[英]Maven: No sources to compile
I am following the 'Build Java Projects with Maven' ( https://spring.io/guides/gs/maven/#scratch ) and when I run 'mvn compile' from /Users/Misha/Desktop/src/main/java/hello, I get this prompt:我正在关注“使用 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] ------------------------------------------------------------------------
I have the two java files and the xml file in the hello directory, and I am assuming that I should see "Hello World."我在 hello 目录中有两个 java 文件和一个 xml 文件,我假设我应该看到“Hello World”。 instead of No sources to compile?
而不是没有编译源? Why is my java code not compiling?
为什么我的 java 代码没有编译? Thanks!
谢谢!
To create a maven-project you need要创建您需要的 Maven 项目
pom.xml
-filepom.xml
文件的项目目录src/main/java
containing your java-code (packages go to subdirectories of src/main/java
)src/main/java
(包转到src/main/java
子目录) To invoke maven run mvn compile
or something similar from the project-directory.要从项目目录中调用 maven run
mvn compile
或类似的东西。
In my case, I was missing this:就我而言,我错过了这个:
<project>
...
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
...
</project>
Normally, I'd just use the default directory structure通常,我只会使用默认的目录结构
src/main/java
as a source folder
. src/main/java
作为source folder
。src/test/java
as a test folder
. src/test/java
作为test folder
。 But I'm working on a class project with existing code, and can't rearrange the file structure.但是我正在使用现有代码处理一个类项目,并且无法重新排列文件结构。
因为$PROJECT_DIR/src/main/java
中没有 java 文件
Are you try to compile project or class ?您是否尝试编译项目或类? As the guideline in https://spring.io/guides/gs/maven/#scratch you need to compile for project.
作为https://spring.io/guides/gs/maven/#scratch 中的指南,您需要为项目编译。 Try to run
mvn compile
from project direction.尝试从项目方向运行
mvn compile
。
In my case, I had to downgrade JDK version from JDK 18 to JDK 17 (IDE: Apache NetBeans 15)就我而言,我不得不将 JDK 版本从 JDK 18 降级到 JDK 17(IDE:Apache NetBeans 15)
I was adding some Java code to a multi-module Kotlin project and in the top level pom.xml
the following was defined:我正在向多模块 Kotlin 项目添加一些 Java 代码,在顶层
pom.xml
中定义了以下内容:
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
So the Java code was never detected by Maven until I added the Java directories to the build configuration:因此,在我将 Java 目录添加到构建配置之前,Maven 从未检测到 Java 代码:
<build>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
...
The recommended git tool is: NONE using credential fcdbaabd-0a76-4111-876f-f6c6a5dfb89a推荐的 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 Fetching changes from the remote Git repository /usr/bin/git config remote.origin.url https://github.com/Ranjithchary/realme-stand.git # timeout=10 Fetching upstream changes from https://github.com/Ranjithchary/realme-stand.git /usr/bin/git --version # timeout=10 git --version # 'git version 2.37.1' using GIT_ASKPASS to set credentials /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 Checking out Revision a37696f887a202dc75b5e7860709b5fff3467998 (refs/remotes/origin/main) /usr/bin/git config core.sparsecheckout # timeout=10 /usr/bin/git checkout -f a37696f887a202dc75b5e7860709b5fff3467998 # timeout=10 Commit message: "files added" /usr/bin/git rev-list --no-walk a37696f887a202dc75b5e7860709b5fff3467998 # timeout=10 [test3] $ mvn mvn
/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 install Error: JAVA_HOME is not defined correctly.
安装错误:JAVA_HOME 未正确定义。 We cannot execute /opt/openjdk-11.0.2_linux-x64/bin/java Build step 'Invoke top-level Maven targets' marked build as failure Finished: FAILURE
我们无法执行 /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.