-1

I have a class, which has a main, which I'm trying to set as a VirtualMachine's agent.

I could extract it as a jar in eclipse, and add it to the build path, everyt time I change it, but that would be a drag.

this:

File f = new File("/FinalProject/src/finalproje/agent.java");
vm.loadAgent(f.getAbsolutePath());

fails to work.

Is there any way to either make this work, or programmatically compile the .jar file from agent.java?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eric Lang
  • 274
  • 1
  • 2
  • 16
  • what is *"extract it as a jar in eclipse*" supposed to mean? What have you tried, exactly? What is your actual question? What are you trying to achieve? – specializt May 20 '16 at 15:00
  • please read about [how to ask a question](https://stackoverflow.com/help/how-to-ask) and [how to provide an MCVE](https://stackoverflow.com/help/mcve) – specializt May 20 '16 at 15:01
  • You execute shell command from your java code. Then you can compile it to jar with a standard [command](https://docs.oracle.com/javase/tutorial/deployment/jar/build.html). Take a look at this: [Execute Shell Code](http://www.mkyong.com/java/how-to-execute-shell-command-from-java/) – Hristo Staykov May 20 '16 at 15:02
  • 1
    This is usually done by using a build tool such as ant, maven or gradle – Aaron May 20 '16 at 15:03

1 Answers1

2

You can use JarOutputStream. I have used this before and it will work for what you are looking to do. Read this answer HERE

Good luck

Community
  • 1
  • 1
apesa
  • 12,163
  • 6
  • 38
  • 43