I have a task of fixing a program written in java, since it was crashing on start. I discovered that the problem was related to a discontinued class in the java library no longer available in 1.8. Eventually I will find an alternative to the library but for right now I need to ship the program with a reference to an old java version NOT installed on the clients computer. What would be the most appropriate way of doing so?
-
The preferred method would be: not allowing this to happen. Either the class is still there, or it has been deprecated since the earliest of times, given you over a decade of warnings. That being said, it is possible to embed a JRE, if I'm not mistaken, but this would mean making the application platform dependent, and providing a version for each platform. My recommendation: fix the problem. – Stultuske May 21 '15 at 11:09
-
1You could try and check the Java version that is used and stop execution if it doesn't match, then inform the user to provide the required version (possibly a range). See here for how to get the version: http://stackoverflow.com/questions/2591083/getting-version-of-java-in-runtime – Thomas May 21 '15 at 11:10
-
If you are using a sun.* class, this is exactly why this is not recommended. – Thorbjørn Ravn Andersen May 21 '15 at 11:11
-
I know guys, it's not recommended. I didn't create the program, a colleague did quite a long time ago. And yes it is a sun class. – Andreas Kruhlmann May 21 '15 at 11:13
-
the most appropriate way: fix it. Otherwise you'll be doing work you don't have to do, for someone who doesn't want to pay for it, while he doesn't want a quick-fix product while he pays for a decent one. – Stultuske May 21 '15 at 11:15
-
@weston what do you mean exactly? Everyone in the office has 1.8 and since it can't run beyond 1.7 it's not possible to reference the class I use. – Andreas Kruhlmann May 21 '15 at 11:16
-
1You could add the sun class to your own project and make it do the right thing until you have the time to actually fix it. Most likely Base64 or similar. – Thorbjørn Ravn Andersen May 21 '15 at 11:16
-
I meant what is reason you can't just fix it now. Is there too much code using sun references? I deleted question because I now see you say you will fix eventually. – weston May 21 '15 at 11:17
-
@weston I got you. Well the problem is, that there is no alternative to the sun reference without using a possibly paid 3rd party library. I need to fix this is a soon as possible so it can run, then I can start implementing an alternative. – Andreas Kruhlmann May 21 '15 at 11:19
-
@ThorbjørnRavnAndersen That might just work. I think I'll give that a go. – Andreas Kruhlmann May 21 '15 at 11:20
-
Can you tell us the class? I'm intrigued about what was in old java and now has no replacement. – weston May 21 '15 at 11:21
-
@weston Absolutely. The class is `sun.jdbc.odbc.JdbcOdbcDriver` There are definetly alternatives to it, although not many as I need to access a paradox database, but again I just needed something to patch the issue. – Andreas Kruhlmann May 21 '15 at 11:26
-
I see, you prob seen this, but just want to link the questions: Related http://stackoverflow.com/questions/14229072/removal-of-jdbc-odbc-bridge-in-java-8 – weston May 21 '15 at 11:32
-
@weston Did see it indeed. It's such old technology, it doesn't surprise me, that my options are limited, but I'll take it as a challenge. – Andreas Kruhlmann May 21 '15 at 11:36
3 Answers
Obviously you want minimal impact on the rest of the code base where you don't want to have to go modifying the imports that may be numerous in your code. So, if the Java version is not installed on the clients computer you'll need to include the class in the packaging of your application.
I would suggest that you create the package structure of wherever the missing class file currently resides such as java.io.x.y.z
so you wont have to modify any of the import statements
e.g. import java.io.x.y.z.ClassName;
Then test test test to ensure it functions as you expect.

- 4,830
- 7
- 36
- 65
The JRE may be distributed with programs. So repackage your program to bundle a JRE and use the java binary from there to start your program.
If you use a wrapper script, this would be where to fix it.

- 73,784
- 33
- 194
- 347
You can use the new javapackager tool and specify the runtime option to include (bundle) a specific JRE.

- 37,247
- 13
- 80
- 152