Skip to content

Simple maven packaging#13

Open
acr31 wants to merge 3 commits intoamidos2006:masterfrom
acr31:maven
Open

Simple maven packaging#13
acr31 wants to merge 3 commits intoamidos2006:masterfrom
acr31:maven

Conversation

@acr31
Copy link
Contributor

@acr31 acr31 commented Apr 13, 2021

No description provided.

acr31 added 2 commits April 13, 2021 15:34
This is needed if you want to jar package this code (for example).
@amidos2006
Copy link
Owner

Just curious about the changes, sorry if I am not very technically deep with Java.
Does these changes break using the framework with using any other building tool beside Maven? Like adding the project to Eclipse?

@acr31
Copy link
Contributor Author

acr31 commented Apr 13, 2021

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.

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation needs fixing

Copy link
Contributor Author

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))) {
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments