4 Replies - 679 Views - Last Post: 29 April 2013 - 03:46 AM Rate Topic: -----

#1 frostshadow5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-April 13

Runnable jar file does not execute code correctly

Posted 28 April 2013 - 07:15 AM

I have made a little game in java and everything has been fine up to this point; when i have tested the game in the eclipse run environment the game works fine and there are no error messages. I then decide to make this into an executable jar file and so, export -> runnable jar file -> exctract packages -> finish. It is now a runnable file.
When running this only certain parts of the code then just decide to work.

For example: the game spawns 'boxes' randomly across the screen (the code works in eclipse just not in the runnable version) :
public void addTimers() {
		boxTimer = new Timer(5, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (boxes.size() < 20 && !titleScreen) {
					boxes.add(new Box(BOARD_WIDTH, BOARD_HEIGHT));
				}
			}
		});
		boxTimer.start();
	} 


Also: if a players health is less than or equal to 0 a win message is displayed (again the code works in exlipse just not in the runnable version):
		} else if (wizard1.getHealth() <= 0) {
			drawWin(wizard2, gx);
		} else if (wizard2.getHealth() <= 0) {
			drawWin(wizard1, gx);
		} 


Here are some of the errors from going to window->show view->error log:

1. While loading class "org.eclipse.team.internal.ccvs.core.CVSWorkspaceSubscriber", thread "Thread[main,6,main]" timed out waiting (5007ms) for thread "Thread[Worker-3,5,main]" to finish starting bundle "org.eclipse.team.cvs.core_3.3.400.I20110510-0800 [251]". To avoid deadlock, thread "Thread[main,6,main]" is proceeding but "org.eclipse.team.internal.ccvs.core.CVSWorkspaceSubscriber" may not be fully initialized.

2. JavaBuilder handling ImageBuilderInternalException while building: Game Practice

3. Resource is out of sync with the file system: '/Game Practice/src/resources/shield.png'.

Here's a stack trace for the first error:

org.eclipse.core.internal.resources.ResourceException: Problems encountered while copying resources.
at org.eclipse.core.internal.localstore.FileSystemResourceManager.copy(FileSystemResourceManager.java:314)
at org.eclipse.core.internal.resources.Resource.copy(Resource.java:542)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.copyResource(AbstractImageBuilder.java:379)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:666)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:545)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:496)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:96)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Contains: Could not read file: L:\Coursework\Computing project\Workspace\Game Practice\src\resources\wizard1win.png.
java.io.FileNotFoundException: L:\Coursework\Computing project\Workspace\Game Practice\src\resources\wizard1win.png (The process cannot access the file because it is being used by another process)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at org.eclipse.core.internal.filesystem.local.LocalFile.openInputStream(LocalFile.java:362)
at org.eclipse.core.filesystem.provider.FileStore.copyFile(FileStore.java:220)
at org.eclipse.core.filesystem.provider.FileStore.copy(FileStore.java:143)
at org.eclipse.core.internal.filesystem.local.LocalFile.copy(LocalFile.java:111)
at org.eclipse.core.internal.localstore.CopyVisitor.copyContents(CopyVisitor.java:100)
at org.eclipse.core.internal.localstore.CopyVisitor.copy(CopyVisitor.java:71)
at org.eclipse.core.internal.localstore.CopyVisitor.visit(CopyVisitor.java:202)
at org.eclipse.core.internal.localstore.UnifiedTree.accept(UnifiedTree.java:110)
at org.eclipse.core.internal.localstore.FileSystemResourceManager.copy(FileSystemResourceManager.java:311)
at org.eclipse.core.internal.resources.Resource.copy(Resource.java:542)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.copyResource(AbstractImageBuilder.java:379)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:666)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:545)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:496)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:96)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

---

Again, these errors don't seem to come up when playing the game in eclipse but when extracted into a runnable jar file happen.

Is This A Good Question/Topic? 0
  • +

Replies To: Runnable jar file does not execute code correctly

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,991
  • Joined: 20-September 08

Re: Runnable jar file does not execute code correctly

Posted 28 April 2013 - 07:43 AM

Quote

java.io.FileNotFoundException: L:\Coursework\Computing project\Workspace\Game Practice\src\resources\wizard1win.png (The process cannot access the file because it is being used by another process)


That's pretty clear. In any case, you should load your resources from the jar

http://technojeeves....va-with-eclipse
Was This Post Helpful? 0
  • +
  • -

#3 frostshadow5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-April 13

Re: Runnable jar file does not execute code correctly

Posted 28 April 2013 - 08:35 AM

My files are correctly placed but i am still having troubles, images do appear on the runnable jar file but the code doesn't execute properly for some strange reason

All files are similar to the following code:
		ImageIcon boxIcon = new ImageIcon(this.getClass().getResource(
				"/images/" + boxType + "Box.png"));
		image = boxIcon.getImage();



Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,991
  • Joined: 20-September 08

Re: Runnable jar file does not execute code correctly

Posted 29 April 2013 - 02:01 AM

Quote

All files are similar to the following code:

OK, that looks not too bad, but from the Eclipse tree it actually looks like image is under resources, in which case, the path would be wrong (should be /resources/images....)

If there are still problems, i'll probably need to see runnable code
Was This Post Helpful? 0
  • +
  • -

#5 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: Runnable jar file does not execute code correctly

Posted 29 April 2013 - 03:46 AM

Quote

L:\Coursework\Computing project\Workspace\Game Practice\src\resources\wizard1win.png (The process cannot access the file because it is being used by another process)


According to this trace, it can find your files, but wizard1win.png (and presumably others, too) is being used by another process. Have you tried running the *.Jar file whilst Eclipse is NOT open? Whilst the files may display properly at first, it's possible that their immutability is causing problems down the track.

Fix this error by freeing up access to your assets, and if the problem persists (or a new problem arises), post it here.

EDIT: Does your program close down neatly? It could be that the assets are still being used residually by the system after your game has terminated (and that Eclipse is allowing your game to run error-free because it forces termination before a new instance of the game can be created). You should shut down your Eclipse IDE and check your Task Manager to see if Java is still using up any memory resources. If it is, forcibly terminate it and then try running your *.Jar file again.

If this is the case, you'll need to remember to free up all resources before you terminate your application.

This post has been edited by Gungnir: 29 April 2013 - 03:57 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1