Getting Java to work in Cygwin

I just downloaded cygwin to run some java programs, and I need to configure java. I tried to load standard linux packages and got an errorCannot execute binary files

After some research, I decided that I had to point it to my java folder for Windows, so I ran

export PATH=$PATH:"/cygdrive/C/Program Files (x86)/Java/jdk1.7.0_51/bin"

and it seems to work (java -version shows my java info). However, this seems to have messed up my linux bash settings, after which I cannot do basic things like ls, sh, etc. It gives the command an error not found, and the only way is to change the PATH variable back to my cygwin folder.

how can i install java in cygwin?

+4
source share
3

-:

Within cygwin, use bash.
Also install java8, older versions lack key features.

-:

Add the following lines to your .bashrc file:
echo "javac     :`which javac`"
echo "jar       :`which jar`"
echo "java      :`which java`"
echo "ant       :`which ant`"

bash, Java. , . , .

src HelloWorld.java:

public class HelloWorld
{
    public static void main(String[] args)
    {
        System.out.println("Hello World from main!");
    }
}

HelloWorldAsPackage.java:

package src;

public class HelloWorldAsPackage
{
    public static void main(String[] args)
    {
        System.out.println("Hello World In a Package (Directory) called 'src'!");
    }
}

bash script runOneCase.bash:

#!/bin/bash

echo "Listing $1.java"
echo "=================================================="
cat $1.java
echo "=================================================="
echo "Compiling $1.java"
echo "+ javac $1.java"
javac $1.java
echo "+ cd $2"
cd $2
echo "Running $1.java"
echo "+ java $3$1 $4"
java $3$1 $4
echo "=================================================="

bash script runThemAll.bash

#!/bin/bash

echo "CASE 1: HelloWorld"
runOneCase.bash HelloWorld . "" ""

echo "CASE 2: HelloWorld as a Package"
runOneCase.bash HelloWorldAsPackage .. src. ""

script: runThemAll.bash, cygwin.

, java, cygwin.

CASE 1: HelloWorld (Hit Return)

Listing HelloWorld.java
==================================================
public class HelloWorld
{
        public static void main(String[] args)
        {
                System.out.println("Hello World from main!");
        }
}
==================================================
Compiling HelloWorld.java
+ javac HelloWorld.java
+ cd .
Running HelloWorld.java
+ java HelloWorld
Hello World from main!
==================================================
CASE 2: HelloWorld as a Package (Hit Return)

Listing HelloWorldAsPackage.java
==================================================
package src;

public class HelloWorldAsPackage
{
        public static void main(String[] args)
        {
                System.out.println("Hello World In a Package (Directory) called 'src'!");
        }
}
==================================================
Compiling HelloWorldAsPackage.java
+ javac HelloWorldAsPackage.java
+ cd ..
Running HelloWorldAsPackage.java
+ java src.HelloWorldAsPackage
Hello World In a Package (Directory) called 'src'!
+1

cygwin java windows. , . Java, .

1. Right-click on 'My Computer' and select 'Properties'.(i.e. go to System Properties)
2. Click on the 'Environment variables' button under the 'Advanced' tab.
3. Alter the 'Path' variable so that it also contains the path to the Java executable.
     Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;C:\Program Files (x86)\Java\jdk1.7.0_51\bin'.

java cygwin, System.

0

ah ha ha rookie mistake. you need to add the java source directory to PATH and not export it directly. So export PATH=$PATH:"/cygdrive/C/Program Files (x86)/Java/jdk1.7.0_51/bin"insteadexport PATH="/cygdrive/C/Program Files (x86)/Java/jdk1.7.0_51/bin

0
source

Source: https://habr.com/ru/post/1541632/