简体   繁体   English

如何将文件夹添加到类路径?

[英]How to add folder to classpath?

I am adding new integration-test for a project.我正在为一个项目添加新的集成测试。 However, I am using vscode, and each time I open Java files under integration-test folder, I got a warning "*.java isn't on the classpath. Only syntax errors will be reported".但是,我使用的是 vscode,每次打开集成测试文件夹下的 Java 文件时,都会收到警告“*.java 不在类路径上。只会报告语法错误”。

I had tried Add A Class-Path Entry To The Manifest , Additional Classpath Elements , etc. However, they couldn't help me to solve it.我曾尝试向清单添加类路径条目附加类路径元素等。但是,他们无法帮助我解决它。

How do I add folder integration-test into classpath?如何将文件夹integration-test添加到类路径中? (.classpath is auto-genrated, I tried to modify it directly, but each time vscode re-open current project will rewrite the content). (.classpath是自动生成的,我试过直接修改,但是每次vscode重新打开当前项目都会重写内容)。 I hope any java files inside integration-test folder will just behave like the ones inside main or test folder.我希望integration-test文件夹中的任何 java 文件的行为都与maintest文件夹中的文件一样。 Especially I hope those test files could work with Java Test Runner extension.特别是我希望这些测试文件可以与 Java Test Runner 扩展一起使用。

Note: I didn't mean to load any resources from integration-test folder.注意:我并不是要从integration-test文件夹中加载任何资源。 I am hoping I could create, edit any Java files inside integration-test folder like all the Java files in main or test folder.我希望我可以创建、编辑integration-test文件夹中的任何 Java 文件,就像main文件夹或test文件夹中的所有 Java 文件一样。 Inside integration-test , it is just like a test folder, had a java folder etc. Right now, vscode will not auto-complete the package path for me when I used intellisense to autocomplete class snippet, and vscode can't recognize any public class that's already in src/main/java/com... .integration-test里面,它就像一个test文件夹,有一个java文件夹等。现在,当我使用intellisense自动完成class片段时,vscode不会为我自动完成包路径,并且vscode无法识别任何公共已经在src/main/java/com...

Current folder structure inside src : src当前文件夹结构: 在此处输入图片说明

Mark the directory as a resources directory using maven-resources-plugin : 使用 maven-resources-plugin将该目录标记为资源目录:

<project>
    ...
    <name>My Resources Plugin Practice Project</name>
    ...
    <build>
        ...
        <resources>
            <resource>
                <directory>src/integration-test/resources</directory>
            </resource>
        </resources>
        ...
    </build>
    ...
</project>

You can also add new test resource folders.您还可以添加新的测试资源文件夹。

<build>
  <testResources>
    <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
    </testResource>
    <testResource>
        <directory>${project.basedir}/src/integration-test/resources</directory>
    </testResource>
  </testResources>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM