Peter F
Peter F

Reputation: 435

Running java from a bat file in such a way that path doesn't need to be specified

I think I have seen this done, but am not sure where. What I want to do is to create a bat file I can package with my class files when sending to a friend to show them progress/ask advice on non programming matters. My friend is not very handy when it comes to code and doesn't like changing computer settings. Just using java myClass as a command line won't work here because although my friend does have java installed, he has not set his windows environment variables so his command prompt knows where to find java.

What kind of line would I need to add to my batch file to make it so it can compensate for problems like this?

Upvotes: 2

Views: 477

Answers (3)

mikeslattery
mikeslattery

Reputation: 4119

Create a manifest file (manifest.txt):

Main-Class: com.mycompany.myapp.MyMainClass

Package your app as a jar:

jar cfm myjarfile.jar manifest.txt *.class

Create a batch file:

start myjarfile.jar

Upvotes: 3

Ayman
Ayman

Reputation: 11585

Use an IDE, NetBeans or eclipse and package your files as a Jar file.. that can be executed directly and you do not need to worry about dependencies, other classes or libraries.

Upvotes: 0

Juned Ahsan
Juned Ahsan

Reputation: 68715

If it is about sharing and running a single java file without jar dependencies. And you are only worried about the java runtime environment setup, then you can use online java code compilers and executors. Here is one:

http://javalaunch.com/JavaLaunch.jsp

You can google for more!

Upvotes: 0

Related Questions