i divided my app development into three modules which needs to be done in 2 languages(Python and java) I have developed one script in python for downloading attachments from a confluence page, But unfortunately i had to develop the other module in JAVA. I need to call the java instance after the python script completed its execution. Is it possible ?.
Asked
Active
Viewed 79 times
-2
-
1It's not really clear what your program is, but one option is two call the java program from Python with `subprocess`. – user202729 Jan 31 '21 at 07:10
-
Yeah the program i am developing with java is using MPXJ dependency , and i tried with subprocess but the dependency is not loading – Naveen Jan 31 '21 at 07:18
-
Post your current code, try to make it a [example]... – user202729 Jan 31 '21 at 07:19
-
Why not use a bash script to run your programs in order? – sepideh_ssh Jan 31 '21 at 08:50
-
Is it possible to have parameter from python to java if i use bash script? – Naveen Jan 31 '21 at 13:40
1 Answers
0
If you use Spring with Java you can use @PostConstruct annotation where you run your python script. The annotated method called after the initialization of your component. As an example:
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.springframework.stereotype.Component;
@Component
public class MyAmazingComponent {
@PostConstruct
private void callScript() {
Process process;
try{
process = Runtime.getRuntime().exec(new String[]{"path/script_python.py","arg1","arg2"});
}catch(Exception e) {
System.out.println("Exception " + e.toString());
}
}
public void doSomething(){...}
}
You need below dependencies for above code (if you use maven of course and versions are not must, you can change them):
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.6.RELEASE</version>
</dependency>

artunc
- 150
- 1
- 7