我之前搜索过很多次好像配置都不怎么成功。 我期望的效果目录下面就一个 pom.xml 管理依赖,App.java 运行代码
--project --App.java --pom.xml
因为不是一整个工程有时候就是一个简单代码可能就一个类不想有这么多层级目录
1
xy2401 OP <build>
<sourceDirectory>./</sourceDirectory> </build> 重新试了一下 mvn 命令支持最后有打包出 class 。eclipse 不支持 run 这个类。idea 支持 run 。vscode 还没有尝试 |
2
john6lq 2021-03-18 08:48:57 +08:00 via iPhone
|
3
xy2401 OP vscode 也不支持
The file App.java isn't on the classpath, the runtime may throw class not found error. Do you want to add the parent folder " " to Java source path? Unsupported operation. Please use pom.xml file to manage the source directories of maven project. |
5
borisz 2021-03-18 11:13:05 +08:00
<plugin>
<groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/../../../../folder1/xxx</source> <source>${basedir}/../../../../folder2/xxx2</source> </sources> </configuration> </execution> </executions> </plugin> |
6
loshine1992 2021-03-18 11:31:48 +08:00
gradle 可以用 sourceSets 配置
|
7
xiaokongwu 2021-03-18 14:25:01 +08:00
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory> <finalName>${project.artifactId}-${project.version}</finalName> <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory> <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> maven 里这是 pom 默认的配置,在<build>标签下,你可以改成你的目录,idea 会识别这个配置,其他 ide 不确定了 |