#compiling java in vscode not working

32 messages · Page 1 of 1 (latest)

devout spire
#

My problem is that vscode isnt compiling my java file.
I type in javac <filename>.java and it just wont compile because it cant recognize a package that I imported. I also cant run it using java <filename>.java
I made sure to use maven for my package manager and I already put the correct dependency in the pom.xml file so everything should be fine. All my path variables and systems variables are also fine so I dont know what else could be wrong?
I tried using the code runner extension and again it didnt work.
On the other hand to compile and run, I had to use the vscode native "Run Java" and this is the only way I can compile and run the program.

Why isnt the terminal command to compile and run not working?

tidal scarabBOT
#

This post has been reserved for your question.

Hey @devout spire! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

devout spire
#

heres the error message

ashen raven
#

you need to pass in dependencies using -cp

#

if you have maven you can use mvn compile to compile

devout spire
#

so compile using mvn compile, then enter java <filenam>.java is this correct?

ashen raven
#

java <filename>, no need to add extension, adding extension will try to compile .java file

devout spire
#

I got a wierd new error

#

I made sure to call java <file> in the correct directory but for some reason it couldnt find it?

ashen raven
#

do you have package declaration in your file?

devout spire
ashen raven
#

no something like package testing?

devout spire
ashen raven
#

what is the first line of App.java?

devout spire
ashen raven
#

^this is your package declaration

#

whats your cwd?

devout spire
ashen raven
#

go back one directory

#

then do java testing.App

#

it should again error out due to missing dependencies

devout spire
#

yep, it didnt error out but it printed some default "hello world" which was there when I made the maven project

ashen raven
#

yeah because newly compiled classes are in target now since you used maven to compile

#

VSCode should be able to run maven projects, do you have all extensions installed?

devout spire
#

It seems like the built in run function in vscode works to compile and run, but why doesnt the terminal way of compiling work for it too?

ashen raven
#

I dont think so, intelliJ is also the same

ashen raven
devout spire
tidal scarabBOT