Using 2 versions of Java

Asked

Viewed 2,698 times

0

My company uses a maintenance-free application that I can’t change, it runs with Java 6.0.17, however in all other applications newer versions of Java are required.

As a solution I made a file .bat to run the old version only in the application that looked like this:

"C:\Program Files (x86)\Java\jdk1.6.0_17\bin\java" -jar ChoppHouse.jar

But the CMD is open all the time and if you close it the application closes together.

I wonder if there is any command to close it without closing the application

3 answers

1

If you know how to edit system variables in windows. The most practical way is to have a variable called JAVA_HOME and in the variable PATH put %JAVA_HOME%/bin

Then you only change the value of JAVA_HOME to the version you want to use. I do so in the company where I work.

1

You can use the command start to call your program and close the prompt with exit:

start "C:\Program Files (x86)\Java\jdk1.6.0_17\bin\java" -jar ChoppHouse.jar
exit

I managed to start Squirrel on my machine using the following script:

start "D:\\app\\tools\\jre1.8.0_151\\bin\\javaw.exe" D:\\app\\tools\\squirrel-new\\squirrel-sql.jar
exit

Edit

I was able to execute also as follows, note that the -jar is inside the quotation marks:

start "D:\\app\\tools\\jre1.8.0_151\\java.exe -jar"  D:\\app\\tools\\squirrel-new\\squirrel-sql.jar

Without the need of exit

  • 1

    I think only start doesn’t work, because java.exe creates a console, you may need to use javaw.exe together with start

  • I tried this setting and the problem is it gives error "Windows cannot find -jar. Make sure the name has been typed correctly"

  • It could be, I can’t test anything right now to simulate behavior, so I check it out

  • And if you don’t use -jar it doesn’t run the application in the old version of Java

  • Using javaw.exe thus "start javaw.exe "C: Program Files (x86) Java jdk1.6.0_17 bin java" -jar Chopphouse.jar Exit" It opens the console and closes but does not run the application

  • I edited the answer with a test script I ran here, I was able to open Squirrel using the way it includes in the answer

  • It opens the same application and closes the CMD, however it opens the application running the latest version of java and not the selected version that in the case is the 6

  • Using start javaw.exe looks like you will use the Java that is in your classpath, you should use javaw or java only in the initial command, as my second response. Running 'start" D: app tools jre1.8.0_151 java.exe -jar" D: app tools Squirrel-new Squirrel-sql.jar' I also managed to open Squirrel

  • Using the last form it opens but continues giving java version error, opens with the last version

  • If possible post the error occurring in the question

  • The error it presents is specific to something that was discontinued from the new versions of JAVA, it presents the error "JDBC-ODBC/Access driver not found!"

Show 6 more comments

0

I suggest, in YOUR CASE, that you create a Windows service. So, when starting Windows it will run in backgroud.

You can use the . bat already made and create a service from it.

Install the NSSM and follow the instructions below:

Run as administrator:

nssm install "ChoppHouseService"

Then a dialog box will appear so you can choose where the file you want to run is.

To uninstall do the following:

nssm remove "ChoppHouseService"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.