I have the following java class that I would like to write a Dockerfile for so that it can be deployed on a container.
package vowelCounter;
import java.util.Scanner;
public class vowelCounter {
public static void main(String args[]){
int count = 0;
System.out.println("Enter a sentence :");
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
for (int i=0 ; i<sentence.length(); i++){
char ch = sentence.charAt(i);
if(ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u'||ch == 'A' ||ch == 'E' ||ch == 'I' ||ch == 'O' ||ch == 'U'){
count ++;
}
}
System.out.println("Number of vowels in the given sentence is "+count);
}
}
Would someone please be able to help me with this, I am new to building dockerfiles for various languages, thanks.
Assuming you have the specified class, compiled into a jar, in, let's say, a directory called target/VowelCounter.jar
then you can use the following Dockerfile:
FROM openjdk:11-jre-slim
COPY target/VowelCounter.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.