Java Maven:没有可编译的源代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27897104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven: No sources to compile
提问by Mikhail Vega
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!" instead of No sources to compile. Why is my java code not compiling? Thanks!
我在 hello 目录中有两个 java 文件和 xml 文件,我假设我应该看到“Hello World!” 而不是没有要编译的来源。为什么我的java代码不能编译?谢谢!
采纳答案by piet.t
To create a maven-project you need
要创建您需要的 Maven 项目
- A project-directory containing the
pom.xml
-file - Within this project-directory a subdirectory
src/main/java
containing your java-code (packages go to subdirectories ofsrc/main/java
)
- 包含
pom.xml
-file 的项目目录 - 在此项目目录中,
src/main/java
包含您的 java 代码的子目录(包转到 的子目录src/main/java
)
To invoke maven run mvn compile
or something similar from the project-directory.
mvn compile
从项目目录中调用 maven run或类似的东西。
回答by piet.t
because there are no java files in $PROJECT_DIR/src/main/java
因为里面没有java文件 $PROJECT_DIR/src/main/java
回答by P.Brian
Are you try to compile project or class ? As the guideline in https://spring.io/guides/gs/maven/#scratchyou need to compile for project.
Try to run mvn compile
from project direction.
您是否尝试编译项目或类?作为https://spring.io/guides/gs/maven/#scratch 中的指南,您需要为项目编译。尝试mvn compile
从项目方向运行。
回答by Cameron Hudson
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 of src/main/java
for my source root and src/test/java
for my test root, but I'm working on a class project with existing code, and can't rearrange the file structure.
通常,我只会src/main/java
为我的源根和src/test/java
测试根使用默认目录结构,但我正在使用现有代码处理一个类项目,并且无法重新排列文件结构。