-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple maven packaging #13
base: master
Are you sure you want to change the base?
Conversation
This is needed if you want to jar package this code (for example).
Just curious about the changes, sorry if I am not very technically deep with Java. |
I don't think so. Actually I've generally found that maven makes it easier to import into different IDEs because many of them can understand it. I use IntelliJ for example and it recognises maven projects and sets them up automatically when you import. |
src/PlayLevel.java
Outdated
MarioGame game = new MarioGame(); | ||
// printResults(game.playGame(getLevel("../levels/original/lvl-1.txt"), 200, 0)); | ||
printResults(game.runGame(new agents.robinBaumgarten.Agent(), getLevel("./levels/original/lvl-1.txt"), 20, 0, true)); | ||
MarioGame game = new MarioGame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation needs fixing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. thanks
try { | ||
content = new String(Files.readAllBytes(Paths.get(filepath))); | ||
} catch (IOException e) { | ||
try (Reader r = new InputStreamReader(PlayLevel.class.getResourceAsStream(filepath))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering what this change is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous version of the code tried to read level files from file paths. This means that you could only use it if you were running the Java code from a particular working directory in the source tree. If you tried to run it somewhere else, or packaged the code in a jar file then it can't load the level. Instead, what this does is load it as a resource - what you do is tell the system which is compiling your code that the levels folder is a resource folder (the maven config does this) and then when the code is built these are copied into the right place and packaged appropriately so that whenever the code is run (either directly or in a jar file) it can find the resources.
(Obviously the previous approach works find for you already so there's no imperative to accept this - but if you want the maven packaging then you should also do this too)
No description provided.