在使用maven编译时,是否有必要在/ src / main / java中使用.java文件? [英] Is it necessary to have .java files in /src/main/java when compiling with maven?
问题描述
我试图将项目转换为maven ...它的.java文件位于/ src / main / java以外的其他位置,当我运行maven install时,所有文件(.hbm,.xml)除外那些.class出现在我的jar中。
I tried to convert a project to a maven one... it has its .java files in other location than /src/main/java , when i run maven install, all the files (.hbm , .xml) except those .class occurs in my jar.
这是来自pom.xml的构建部分:
This is build part from pom.xml :
<build>
<resources>
<resource>
<directory>${basedir}/src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<compilerVersion>1.5</compilerVersion>
<compilerArguments>
<encoding>UTF-8</encoding>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
使用上面的代码,我的jar中缺少.class文件......并且没有错误消息显示在控制台上,是否有必要将它们移动到/ src / main / java包结构?
Using the above code, .class files are missing from my jar... and no error messages are displayed on console, is it necessary to move them to /src/main/java package structure ?
此外,这种行为可能是什么原因,一些缺少依赖性?
Also, what could be the reason for this behavior , some missing dependencies ?
我做了一个更改,将它们移动到src / main / java,我在控制台上有一些例外,但如果我必须将它们添加到此,我仍然感到困惑src / main / java结构...
I did a change moving them to , src/main/java and i got some exceptions on console , but i am still confused if i "must" add them to this "src/main/java" structure...
请给我一个关于此的想法......
Please give me an idea about this...
谢谢
推荐答案
您可以将源目录配置为与以下资源相同:
You can configure the source directory to be the same as the resources like this:
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
这篇关于在使用maven编译时,是否有必要在/ src / main / java中使用.java文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!