返回信息流更新:mvn clean以后既可以了
[Spring中的maven教程](https://spring.io/guides/gs/maven/#scratch)
我是按这个教程一步步来的,POM完全copy的上面的,然后java文件里面就是调用了这个东西
```LocalTime currentTime = new LocalTime();```
然后POM里面按照教程说的增添了依赖:
```
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
```
然而还是出现了下面的错误
>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default->compile) on project gs-maven: Compilation failure: Compilation failure:
>[ERROR] /D:/Codes/JavaProject/maven_test/src/main/java/hello/helloworld.java:[5,9] 找不到符号
>[ERROR] 符号: 类 LocalTime
>[ERROR] 位置: 类 main.java.hello.helloworld
>[ERROR] /D:/Codes/JavaProject/maven_test/src/main/java/hello/helloworld.java:[5,37] 找不到符号
>[ERROR] 符号: 类 LocalTime
>[ERROR] 位置: 类 main.java.hello.helloworld
我以为在POM里加了依赖他不是就会自动从Central repository里下载包了吗...小白不懂求教啊
这是一条镜像帖。来源:北邮人论坛 / java / #51122同步于 2016/6/21
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
按照Maven文档配置Dependence时出错
VictorLees
2016/6/21镜像同步13 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
我感觉我基本上没用IDE啊,用myeclipse起到的作用和写字板一样,编译那些都是在控制台做的。
我在IDE里面看到POM文件的Dependence里面添加好了joda-time这一项的,但不知道为啥会找不到localtime这个类
【 在 maoxian 的大作中提到: 】
: 你用的什么ide?
: IDEA里有个reimport,可以试一下
: 也可以设置修改pom.xml后自动导入
mvn compile报的错好像和mvn package一样额..
我应该是没用ide的,编译都是在cmd上直接输入mvn的啊,也可能是我不太懂
我把完整的信息贴上来,麻烦暖神帮忙看一眼
>D:\Codes\JavaProject\maven_test>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] skip non existing resourceDirectory D:\Codes\JavaProject\maven_test\src\main\resources
>[INFO]
>[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gs-maven ---
>[INFO] Changes detected - recompiling the module!
>[INFO] Compiling 2 source files to D:\Codes\JavaProject\maven_test\target\classes
>[INFO] -------------------------------------------------------------
>[ERROR] COMPILATION ERROR :
>[INFO] -------------------------------------------------------------
>[ERROR] /D:/Codes/JavaProject/maven_test/src/main/java/hello/helloworld.java:[5,9] 找不到符号
> 符号: 类 LocalTime
> 位置: 类 main.java.hello.helloworld
>[ERROR] /D:/Codes/JavaProject/maven_test/src/main/java/hello/helloworld.java:[5,37] 找不到符号
> 符号: 类 LocalTime
> 位置: 类 main.java.hello.helloworld
>[INFO] 2 errors
>[INFO] -------------------------------------------------------------
>[INFO] ------------------------------------------------------------------------
>[INFO] BUILD FAILURE
>[INFO] ------------------------------------------------------------------------
>[INFO] Total time: 0.932 s
>[INFO] Finished at: 2016-06-22T09:34:03+08:00
>[INFO] Final Memory: 11M/26M
>[INFO] ------------------------------------------------------------------------
>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default->compile) on project gs-maven: Compilation failure: Compilation failure:
>[ERROR] /D:/Codes/JavaProject/maven_test/src/main/java/hello/helloworld.java:[5,9] 找不到符号
>[ERROR] 符号: 类 LocalTime
>[ERROR] 位置: 类 main.java.hello.helloworld
>[ERROR] /D:/Codes/JavaProject/maven_test/src/main/java/hello/helloworld.java:[5,37] 找不到符号
>[ERROR] 符号: 类 LocalTime
>[ERROR] 位置: 类 main.java.hello.helloworld
>[ERROR] -> [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] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
【 在 nuanyangyang 的大作中提到: 】
: 你用ide了?看样子你的编译器认为源代码存在src目录里,但实际上是在src/main/java里。
: 你输入mvn compile试试看?
目录结构很简单
|---maven_test
|---src
|---main.java.hello
|---Greeter.java
|---helloworld.java
POM文件如下
```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<!-- tag::joda[] -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<!-- end::joda[] -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
```
然后下面是helloworld.java
Greeter.java就是一句输出
```
package main.java.hello;
public class helloworld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
```
【 在 nuanyangyang 的大作中提到: 】
: 贴你整个目录结构吧。还有整个pom
main.java.hello
是这个目录。
应该是src目录下有一个main目录,main里面有一个java目录。java目录里有一个hello目录。hello目录下有一个helloworld.java(更好的应该叫HelloWorld.java,符合Java的大小写习惯)。而且helloworld.java里面,package应该是hello,不包括main和java。
目录结构确实是这样,但是...为什么会出问题呢?又怎么解决呢?没太看懂...
【 在 nuanyangyang 的大作中提到: 】
: main.java.hello
: 是这个目录。
: 应该是src目录下有一个main目录,main里面有一个java目录。java目录里有一个hello目录。hello目录下有一个helloworld.java(更好的应该叫HelloWorld.java,符合Java的大小写习惯)。而且helloworld.java里面,package应该是hello,不包括main和java。