0

I have Java project in Android Studio. I am able to launch and test it from Studio, but I have no idea of how to build it and get an executable jar file. Need help how to do that. I see some jar files in the "build/libs/" directory but thats not what i need.

Fedor
  • 83
  • 1
  • 9
  • When you say 'Java project' do you mean an android app or are you using Android Studio as your IDE for a non-Android project? – jonk Oct 27 '16 at 13:45
  • No. I mean Android Studio as IDE for non-android project – Fedor Oct 27 '16 at 13:48
  • 1
    In that case use either maven or gradle to create an executable jar as part of the build process ([maven example](https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html), [gradle example](http://stackoverflow.com/questions/21721119/creating-runnable-jar-with-gradle)). FYI Android Studio is based on IntelliJ IDEA Community Edition so might be worth switching to that to remove Android specific stuff that is of no use to you. – jonk Oct 27 '16 at 13:53
  • attributes 'Main-Class': 'com.foo.bar.MainClass' - here i need to declare my main class, am i right?) – Fedor Oct 27 '16 at 13:58
  • I take it that means you're using gradle, if so yes. – jonk Oct 27 '16 at 14:02
  • okay, thanks will try these solutions) – Fedor Oct 27 '16 at 14:09

1 Answers1

0

So first of all Android Studio is the official integrated development environment (IDE) for Android platform development and for Java projects (as well). Yes you can create and execute java projects hassle free but when it comes to making a Java Archive or an executable JAR then it becomes really unpleasant (there's no easy way to do this). But if you still want to go for it then maybe this will help you.

Anyways being a Java/Android programmer myself I prefer doing tasks on separate IDEs. For Java I use Eclipse-Neon. Exporting a JAR, or an exec-JAR learn how.

If you're adamant about using the Studio then I'd recommend you to start new by choosing java module as the project type.

Hope this helps.

Thanks

Han
  • 575
  • 8
  • 21
  • 1
    I would not recommend completely switching to Eclipse just to write a Java app. Android Studio is more than capable. If not, then using vanilla IntelliJ IDEA with the Android plugin is more preferred. – OneCricketeer Oct 27 '16 at 17:59
  • Thanks for the answer! I'll try this solution) – Fedor Oct 28 '16 at 07:38