0

Hi I wrote wordquiz program on Java. Using Eclipse in Unix. In my linux machine it works fine. Here is a source code https://github.com/HighlanderGe/Words So, only basic package is used. In windows compilation of such code as jar doesn't run. Neither in Mac. As I guess problem is that in linux it is made to run from console, and console is comething very native for linux, but in Windows and I think in Mac too, cmd should be called, and from there it somehow to run.. but I bet cmd has no idea what is java. So some java console is needed for it?

6
  • Did you try to export executable jar and run it on any other platform? This usualy works. Commented Feb 15, 2014 at 10:27
  • 2
    Have you tried to run cmd.exe, go to the right directory, and then type java -jar myjar.jar or java -cp myjar.jar my.main.Class ? What happened? Commented Feb 15, 2014 at 10:29
  • Did you install java on your windows? Commented Feb 15, 2014 at 10:31
  • Yes sure Java is installed on Windows. On the both systems I use Eclipse Commented Feb 15, 2014 at 10:32
  • Erwin Bolwidt - it works so!!! How to make one exe file, so that cmd will run with this command and executes jar file? Commented Feb 15, 2014 at 10:38

2 Answers 2

1

The problem is not with the Mac or Windows, the problem is that you did not setup your workspace in Eclipse the same way on your different computers.

You can build your program on the command line in all environments in the same way. You just have to know the right steps.

First of all, there's an error in your code on line 25 in WordDatabase. Instead of:

dictionary = new ArrayList<>();

it should be:

dictionary = new ArrayList<String>();

After that, you can build your code like this:

javac -d . *.java

And run it like this:

java wordquizz/Wordquizz

This should work in any system that has Java, you just need to figure out how to setup your workspace in Eclipse the same way on your different computers.

UPDATE

I forked and converted your project to a Maven project:

https://github.com/janosgyerik/StackOverflow-Words

After you clone this to your PC, you can import into Eclipse using the File | Import... menu, and then Existing Maven projects option. It should work on all operating systems.

Maven is a recommended tool for building Java projects and it's a good thing to learn. After you install maven, you can build the project with:

mvn compile

You can package the project into a jar file with:

mvn package

You can run your code with either of these commands:

# needs 'mvn compile' first to generate classes
java -cp target/classes/ wordquizz.Wordquizz

# needs 'mvn package' first to generate the jar
java -cp target/wordquizz-1.0-SNAPSHOT.jar wordquizz.Wordquizz 

If you like these improvements, merge from my repo soon. I won't keep it forever, I will delete it at some point.

UPDATE 2

To make a jar executable, you need to add inside a manifest file like this:

Main-Class: wordquizz.Wordquizz

You create the jar file with a command like this:

jar cvfm package.jar manifest.txt wordquizz/*.class

I updated my GitHub repository, so that now if you run mvn package, it will automatically add the right manifest, and the generated jar file will be executable.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for answer, it is fixed now... Current issue is to make single exe file to run cmd and execute command java -jar myjar.jar
Don't do this. Use a native wrapper that embeds the .jar on compile to native code with a commercial product like Excelsior Jet.
0

If you installed java under windows you have to adjust the Path-variable, so the cmd knows where the java executable is. A good tutorial on how to set this up you can find here:

http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

After that you can simple go to the directory your source code is in and use the same commands as under linux to compile and run your application.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.