Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

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? (.classpath is auto-genrated, I tried to modify it directly, but each time vscode re-open current project will rewrite the content). I hope any java files inside integration-test folder will just behave like the ones inside main or test folder. Especially I hope those test files could work with Java Test Runner extension.

Note: I didn't mean to load any resources from integration-test folder. I am hoping I could create, edit any Java files inside integration-test folder like all the Java files in main or test folder. 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....

Current folder structure inside src: enter image description here

like image 225
Jiahua Zhang Avatar asked Mar 21 '26 09:03

Jiahua Zhang


1 Answers

Mark the directory as a resources directory using maven-resources-plugin:

<project>
    ...
    <name>My Resources Plugin Practice Project</name>
    ...
    <build>
        ...
        <resources>
            <resource>
                <directory>src/integration-test/resources</directory>
            </resource>
        </resources>
        ...
    </build>
    ...
</project>
like image 121
madhead - StandWithUkraine Avatar answered Mar 24 '26 00:03

madhead - StandWithUkraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!