Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:41:59+00:00 2026-06-12T13:41:59+00:00

I have a Java program, and write a makefile to compile it on Linux.

  • 0

I have a Java program, and write a makefile to compile it on Linux.

My project organized like this (Run.java is the main entry)

Program - 
   Src - 
       (package)adb.Bing_WebResults
            Run.java
       (package)adb.jsonModel
            *.java
       (package)adb.models
            *.java
   bin - 

   lib - 
       gson.jar
       commons.jar

   resource -
       *.txt

This is my makefile:

# My project require 3 parameters from user input.

default: Run.class
Run.class: src/adb/Bing_WebResults/Run.java
    javac -sourcepath src/ -classpath lib/*.jar -d bin/ src/adb/Bing_WebResults/*.java  src/adb/jsonModels/*.java src/adb/models/*.java


run:
    java -classpath bin/:lib/*.jar  Run  "$(ARG1)" "$(ARG2)" "$(ARG3)"

When I use “make run” command in Linux terminate, exception shows that “Could not find the main class: Run”

Are there something wrong with my makefile? Wrong path or something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:42:01+00:00Added an answer on June 12, 2026 at 1:42 pm

    There are many things that could potentially be wrong, but the most apparent issues are the incorrect dependencies of the targets in your makefile.

    First of all, the target run should have a dependency on Run.class. If you do make run then make looks at the target called run. In your makefile, this target does not have any dependencies defined, and it will execute the line java ... without checking whether the actual compiled class Run.class exists. As a consequence, if you do make run from a clean situation, your source code will not be compiled and the java command will fail because the compiled class is missing.

    Your dependency of default on Run.class is incorrect as well, because Run.class will exist in the bin directory, not in the working directory. The line below mentions the target Run.class as well.

    There are several ways to improve your makefile. See below an example of corrected code with some variables added to avoid repeated expressions. This approach is a matter of style and preference though.

    BINDIR := bin
    RUNCLASS := Run
    RUNBINARY := $(BINDIR)/$(RUNCLASS).class
    SRCDIR := src/adb/Bing_WebResults
    RUNSRC := $(SRCDIR)/$(RUNCLASS).java
    
    # Note: the default target below is superfluous at this moment
    default: $(RUNBINARY)
    $(RUNBINARY): $(RUNSRC)
            javac -sourcepath src/ -classpath lib/*.jar -d $(BINDIR) $(SRCDIR)/*.java src/adb/jsonModels/*.java src/adb/models/*.java
    
    run: $(RUNBINARY)
            java -classpath $(BINDIR):lib/*.jar  $(RUNCLASS)  "$(ARG1)" "$(ARG2)" "$(ARG3)"
    

    This works for me in a simplified, comparable setup — it might work for you as well. Looking at the snippet you provided, there are most likely other dependencies or changes that need to be added to complete your makefile correctly. Potentially, you might have to add package information to your run command and dependency expressions, but that depends on your source code. Your post does not contain enough information to provide a complete solution.

    P.S.: Do not forget to replace spaces by tabs if you copy this code to your own makefile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asked to write a java program on linux platform. According to
I have to write a Java program that tells what coins to give out
How to write a java program which will tell me whether I have internet
I have a java program that performs 5 different tasks. When I run the
I have a java program that is running in the background(Windows). I would like
I have to write a little Java program that stands in the middle of
I have a dummy Java Program, which I want to write in Clojure. It
I have a database and a Java Program. I am trying to write a
I have a Java program aiming to consider an xml dom and write it
I have a java program which I run on a home server. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.