Ask coding questions

← Back to all posts
Help, express with java aint workin :(
EpicGamer007 (1614)

I recently found a really cool port of the nodejs library expressjs to java here.

Though while trying to get it to work, I have encountered a really really annoying error with java-express and I am not sure if its my fault or theirs.

Before I explain the problem, Let me explain the file structure.

bin // Where .class files go
lib // Where express.jar goes
src // source
|--- public // Static files such as scripts, styles, and images
|--- routes // folder which contains routes
|--- |--- Router.java // A file which makes the path / in the server go to index.html from the views
|--- views // html files
|--- |--- index.html // Main file
|--- Configuration.java // Configuration for server, contains startup runner
|--- Main.java // Main code
.replit // .replit
main.sh // bash file I run
README.md // Random stuff I used for testing

My problem is with line 39 of Main.java.
Whenever I try to use the statics method, it does not work. I go to /scripts/script.js for example, but it never loads.

I am not sure if its a problem with me or the library.
This is the code for Middleware.statics():

public static FileProvider statics(String directoryPath, FileProviderOptions staticOptions) throws IOException {
    return new FileProvider(directoryPath, staticOptions);
}

And the class FileProvider is here.

If anyone can help with this, it would be really appreciated.

Thanks to all answers

Comments
hotnewtop
Coder100 (17020)

Oh i see. Here's the thing, the binary isn't actually where you expected it to be. It's in bin. Your public stuffs are in src/public, and user.dir points it to .../bin, not in .../src!!

EpicGamer007 (1614)

@Coder100

String currentPath = Paths.get(							 
    System.getProperty("user.dir")
).toString();

String folderPath = Paths.get(
	currentPath.substring(0, currentPath.length() - 4),
	"src", 
	"public"
).toString();
			
System.out.println(folderPath);

this is the code i have to get the directory, the system.out.printlne below it prints /home/runner/JShort/src/public, which is where it is trying to go. And i purposefully made the bimary go in bin with the -d in the javac. and what is .../bin?

Coder100 (17020)

oh yeah .../bin was shortened of home/runner/JShort/bin xd @EpicGamer007

EpicGamer007 (1614)

@Coder100 do you have any idea on how to fix it?