• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to build/run a java project on linux system using bash?  RSS feed

 
Alex Yan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have a java project in intellij right now. I'm trying to get it to run through ssh on a linux system.

I've uploaded the class files, however The project will not run unless I take out all the package declarations and rebuild the project.

Whats the correct way to build/run a java project using bash? I think I just need the right commands for it to recognize packages.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

Welcome to JavaRanch!

The command for running a Java program on Linux is the same as for running on Windows. It can be tricky to get the classes in the right directories on any system. Let's say your main method is in Hello.class in the com.net.org.me package. You would need to have that class in a directory structure mimicking the package. Like




All other classes would have to be in directories matching their packages as well. Then from the myroot directory, you'd enter:

java -cp . com.net.org.me.Hello


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:The command for running a Java program on Linux is the same as for running on Windows.

Almost. The path separator is : versus ;
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D'oh! Well, if your classpath only has one element, then it's the same. Otherwise it's almost the same. As the saying goes though, "almost" only counts in horseshoes and hand grenades.


(And hydrogen bombs.)
 
Alex Yan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I think I may have to build the project on the linux machine using javac.

Can someone show me a sample of how to build and run the project?

Thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For building Java projects that consist of more than a handful of source files, you'll want to use a build tool. The most popular build tools for Java are Apache Ant and Apache Maven. I'd start with Ant if you're unfamiliar with such tools; it's relatively simple and works well. (Maven does a lot more, it automates dependency management for you, but it's also more complicated than Ant).

You just run Ant from the command line (or a terminal window on Unix) to compile your code; you'll not need the complete IDE to build your project.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!