2

I have written a small java application for one of my homework. the problem is the teacher may not have JRE installed. what i want to id to compile the java file to window exe file so the teacher can run it without the JRE installed.

i use the gcj tool in the cygwin , but the output application seem to need the cygwin1.dll to run. how can i avoid this, IE package all the things the application need to a single file, so the teacher don't have to install anything.

Cœur
  • 37,241
  • 25
  • 195
  • 267
danny
  • 1,095
  • 2
  • 12
  • 27

3 Answers3

1

Use MinGW instead of Cygwin.

And get ready for a 10-MiB executable.

user541686
  • 205,094
  • 128
  • 528
  • 886
  • MinGW doesn't have a Java compiler (hence the "Min" bit). You may be able to get it from the ports but you'll be building from source. – paxdiablo Jun 03 '11 at 04:01
  • 1
    @paxdiablo: That's not true, [it *does* have a Java compiler](http://www.mingw.org/wiki/Compile_with_gcj). (See [here](http://sourceforge.net/projects/mingw/files/MinGW/BaseSystem/GCC/Version4/Previous%20Release%20gcc-4.4.0/) for a download.) And it works well, unless you want to do GUI things (Swing, etc.), in which case it doesn't really work. – user541686 Jun 03 '11 at 04:13
  • It's not in the latest builds (any of the 4.5 ones): see http://stackoverflow.com/questions/5001661/mingw-gcj-for-windows/5001759#5001759 - as I noted in that answer, you _can_ go back to the 4.4 stream. That's probably not too bad a solution if you really need Java support. – paxdiablo Jun 03 '11 at 04:17
  • @paxdiablo: LOLLLLL I feel kinda stupid right now, I totally didn't notice you yourself had answered me. xD But then why did you say it doesn't have it? You kinda answered it yourself... – user541686 Jun 03 '11 at 04:20
  • @paxdiablo: Actually, I currently have version 4.7.0 of GCJ. [The only trouble I'm having is that it seems to depend on ECJ, which I have no idea where to find.](http://stackoverflow.com/questions/5625800/gcc-gcj-needs-ecj-and-other-libraries) :( – user541686 Jun 03 '11 at 04:21
  • Err, that's the Eclipse Java Compiler, the one that lets Eclipse compile Java without an underlying JDK. Most likely you could find it somewhere on the Eclipse site - let me know how that works out, I've sometimes spent days in there just looking for stuff :-) – paxdiablo Jun 03 '11 at 04:22
  • @paxdiablo: Yeah I realized that's what the `E` stood for, but I can't figure out where to download it... any ideas? – user541686 Jun 03 '11 at 04:23
1

Why don't you just ask your teacher to install a JRE, or if they have one? If you are allowed to use Java, then I'm certain the teacher will be required to have the tools for properly evaluating your homework.

If you weren't allowed to use Java, well then, what were were you thinking?

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Maybe he/she is a math teacher not a software related teacher. – Enrique Jun 03 '11 at 04:01
  • 1
    @Enrique, that hopefully won't matter. If the teacher has explicitly allowed certain tools to be used, it's their responsibility to provide an evaluation environment. Not doing so (at least when I went to University which, admittedly, was a while ago) was grounds for disciplinary action. In any case, asking is the right thing to do. It puts the teacher on notice and allows the student to rework if indded the teacher will not do so. – paxdiablo Jun 03 '11 at 04:03
  • yes,that is the situation, this is a computing Algorithm course,and the teacher really don't care that much about the program, she can't read it be it c++ or java, since i am learning java, so i choose go with java. – danny Jun 03 '11 at 04:06
  • 3
    @danny: _talk_ to the teacher. Now! Better to get this out of the way early. – paxdiablo Jun 03 '11 at 04:10
  • The essence of this question is how to create a Windows.EXE using Cygwin tools which does not require cygwin1.dll, from a Java program. I think that's a good question on its own. The fact that there's a teacher involved, etc., is only incidental. Someone might well be faced with this situation outside of school. So I think this answer is irrelevant for Stack Overflow. Possibly it would have been appropriate for a comment. – skiphoppy Sep 27 '12 at 19:55
0

The application seem to need the cygwin1.dll to run.

Shipping an .exe with an cluster of .dll files is the norm on Windows.

If you use Microsoft Visual Studio, your program will also need be shipped with some libraries from the Visual Studio Redistributable Run-Time. (Unless you link it statically.) Most major applications on Windows have installation directories chock full of dll files, and won't run without them.

In the middle of 2016, the Cygwin project changed the licensing from GPL to LGPL. This means you can link programs with to cygwin1.dll and redistribute them, even if those programs have a license that is not compatible with the regular GPL, such as closed-source, non-freely-redistributable, proprietary programs. (If you otherwise comply with the LGPL in regard to how you are redistributing cygwin1.dll itself, of course).

IE package all the things the application need to a single file, so the teacher don't have to install anything.

The only way not to install anything is not to have a file at all. If there is a single file it has to be put somewhere, and that meets the definition of installation. On Windows, if you have a .exe file that depends on a .dll, all you have to ensure is that they are put into the same directory. This requirement can be met as easily as by putting them into a .zip file, if the program is too unimportant to warrant developing a full blown installer.

Your teacher unzips your .zip file on their Desktop, or in their Downloads directory. A folder should appear, and in that folder is your program and the dll. The program can be invoked and loads the dll; no brainer.

Kaz
  • 55,781
  • 9
  • 100
  • 149