Compile Multiple Classes and pass command line arguments





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















How would I compile two classes using command line(without the use of additional software) and pass arguments to it?



I've created myself a sources.txt file which contains definitions where each class is. I did this by using the following command



dir /s /B *.java > sources.txt


Then I try to do javac @sources.txt although that does not help as I'm getting the following error:



error: invalid flag: C:UsersAdrian
Usage: javac <options> <source files>
use --help for a list of possible options


Additionally, my path does contain one space, after my username. Adrian $. So in sources.txt it looks like this: C:UsersAdrian $



I did try putting quotes around them or percentage sign but then I get error which specifies that the file was not found.





Full Main code:



package me.adrian;

import java.io.FileNotFoundException;

public class Main {

public static void main(String args) {
CSVoperator CSVfile = new CSVoperator();

try {
CSVfile.readCSV(args); //get args into there.
}
catch (FileNotFoundException e){
e.printStackTrace();
}
}

}









share|improve this question































    1















    How would I compile two classes using command line(without the use of additional software) and pass arguments to it?



    I've created myself a sources.txt file which contains definitions where each class is. I did this by using the following command



    dir /s /B *.java > sources.txt


    Then I try to do javac @sources.txt although that does not help as I'm getting the following error:



    error: invalid flag: C:UsersAdrian
    Usage: javac <options> <source files>
    use --help for a list of possible options


    Additionally, my path does contain one space, after my username. Adrian $. So in sources.txt it looks like this: C:UsersAdrian $



    I did try putting quotes around them or percentage sign but then I get error which specifies that the file was not found.





    Full Main code:



    package me.adrian;

    import java.io.FileNotFoundException;

    public class Main {

    public static void main(String args) {
    CSVoperator CSVfile = new CSVoperator();

    try {
    CSVfile.readCSV(args); //get args into there.
    }
    catch (FileNotFoundException e){
    e.printStackTrace();
    }
    }

    }









    share|improve this question



























      1












      1








      1








      How would I compile two classes using command line(without the use of additional software) and pass arguments to it?



      I've created myself a sources.txt file which contains definitions where each class is. I did this by using the following command



      dir /s /B *.java > sources.txt


      Then I try to do javac @sources.txt although that does not help as I'm getting the following error:



      error: invalid flag: C:UsersAdrian
      Usage: javac <options> <source files>
      use --help for a list of possible options


      Additionally, my path does contain one space, after my username. Adrian $. So in sources.txt it looks like this: C:UsersAdrian $



      I did try putting quotes around them or percentage sign but then I get error which specifies that the file was not found.





      Full Main code:



      package me.adrian;

      import java.io.FileNotFoundException;

      public class Main {

      public static void main(String args) {
      CSVoperator CSVfile = new CSVoperator();

      try {
      CSVfile.readCSV(args); //get args into there.
      }
      catch (FileNotFoundException e){
      e.printStackTrace();
      }
      }

      }









      share|improve this question
















      How would I compile two classes using command line(without the use of additional software) and pass arguments to it?



      I've created myself a sources.txt file which contains definitions where each class is. I did this by using the following command



      dir /s /B *.java > sources.txt


      Then I try to do javac @sources.txt although that does not help as I'm getting the following error:



      error: invalid flag: C:UsersAdrian
      Usage: javac <options> <source files>
      use --help for a list of possible options


      Additionally, my path does contain one space, after my username. Adrian $. So in sources.txt it looks like this: C:UsersAdrian $



      I did try putting quotes around them or percentage sign but then I get error which specifies that the file was not found.





      Full Main code:



      package me.adrian;

      import java.io.FileNotFoundException;

      public class Main {

      public static void main(String args) {
      CSVoperator CSVfile = new CSVoperator();

      try {
      CSVfile.readCSV(args); //get args into there.
      }
      catch (FileNotFoundException e){
      e.printStackTrace();
      }
      }

      }






      java javac






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 21:22







      Adrian

















      asked Nov 16 '18 at 20:49









      AdrianAdrian

      387




      387
























          2 Answers
          2






          active

          oldest

          votes


















          1














          You can compile directly by specifying multiple names in on command



          javac file1.java file2.java


          or by using *, all .java files that are in current directory will be compiled



          javac *.java





          share|improve this answer
























          • Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

            – Adrian
            Nov 16 '18 at 20:55











          • which operating system? , it works for me in windows @Adrian

            – Deadpool
            Nov 16 '18 at 20:58











          • I'm using Windows 10. jdk 11.0.1

            – Adrian
            Nov 16 '18 at 20:59













          • okay, which version java? and do you any .java files in that directory, you should execute this from that directory

            – Deadpool
            Nov 16 '18 at 20:59











          • Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

            – Adrian
            Nov 16 '18 at 21:02



















          0














          Since your paths contain space they has to be quoted. You can do it by iterating over sources.txt in a loop and quoting the entire line:



          FOR /F %%i IN (sources.txt) DO "javac %%i"


          or you can try dir /x to generate sources.txt with a short path as per dir docs




          /x



          Displays the short names generated for non-8dot3 file names. The display is the same as the display for /n, but the short name is inserted before the long name.




          One way or another, scripting in Windows Batch sux.






          share|improve this answer


























          • If this would help then %%i was unexpected at this time.

            – Adrian
            Nov 16 '18 at 21:10











          • @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

            – Karol Dowbecki
            Nov 16 '18 at 21:13













          • My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

            – Adrian
            Nov 16 '18 at 21:16











          • @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

            – Karol Dowbecki
            Nov 16 '18 at 21:19











          • I have updated this question with my main.java code.

            – Adrian
            Nov 16 '18 at 21:23












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345175%2fcompile-multiple-classes-and-pass-command-line-arguments%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can compile directly by specifying multiple names in on command



          javac file1.java file2.java


          or by using *, all .java files that are in current directory will be compiled



          javac *.java





          share|improve this answer
























          • Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

            – Adrian
            Nov 16 '18 at 20:55











          • which operating system? , it works for me in windows @Adrian

            – Deadpool
            Nov 16 '18 at 20:58











          • I'm using Windows 10. jdk 11.0.1

            – Adrian
            Nov 16 '18 at 20:59













          • okay, which version java? and do you any .java files in that directory, you should execute this from that directory

            – Deadpool
            Nov 16 '18 at 20:59











          • Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

            – Adrian
            Nov 16 '18 at 21:02
















          1














          You can compile directly by specifying multiple names in on command



          javac file1.java file2.java


          or by using *, all .java files that are in current directory will be compiled



          javac *.java





          share|improve this answer
























          • Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

            – Adrian
            Nov 16 '18 at 20:55











          • which operating system? , it works for me in windows @Adrian

            – Deadpool
            Nov 16 '18 at 20:58











          • I'm using Windows 10. jdk 11.0.1

            – Adrian
            Nov 16 '18 at 20:59













          • okay, which version java? and do you any .java files in that directory, you should execute this from that directory

            – Deadpool
            Nov 16 '18 at 20:59











          • Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

            – Adrian
            Nov 16 '18 at 21:02














          1












          1








          1







          You can compile directly by specifying multiple names in on command



          javac file1.java file2.java


          or by using *, all .java files that are in current directory will be compiled



          javac *.java





          share|improve this answer













          You can compile directly by specifying multiple names in on command



          javac file1.java file2.java


          or by using *, all .java files that are in current directory will be compiled



          javac *.java






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 20:53









          DeadpoolDeadpool

          8,0822831




          8,0822831













          • Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

            – Adrian
            Nov 16 '18 at 20:55











          • which operating system? , it works for me in windows @Adrian

            – Deadpool
            Nov 16 '18 at 20:58











          • I'm using Windows 10. jdk 11.0.1

            – Adrian
            Nov 16 '18 at 20:59













          • okay, which version java? and do you any .java files in that directory, you should execute this from that directory

            – Deadpool
            Nov 16 '18 at 20:59











          • Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

            – Adrian
            Nov 16 '18 at 21:02



















          • Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

            – Adrian
            Nov 16 '18 at 20:55











          • which operating system? , it works for me in windows @Adrian

            – Deadpool
            Nov 16 '18 at 20:58











          • I'm using Windows 10. jdk 11.0.1

            – Adrian
            Nov 16 '18 at 20:59













          • okay, which version java? and do you any .java files in that directory, you should execute this from that directory

            – Deadpool
            Nov 16 '18 at 20:59











          • Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

            – Adrian
            Nov 16 '18 at 21:02

















          Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

          – Adrian
          Nov 16 '18 at 20:55





          Thanks! Although when I try to run them then I get Error: Could not find or load main class *.java Caused by: java.lang.ClassNotFoundException: *.java I used java *.java to run it.

          – Adrian
          Nov 16 '18 at 20:55













          which operating system? , it works for me in windows @Adrian

          – Deadpool
          Nov 16 '18 at 20:58





          which operating system? , it works for me in windows @Adrian

          – Deadpool
          Nov 16 '18 at 20:58













          I'm using Windows 10. jdk 11.0.1

          – Adrian
          Nov 16 '18 at 20:59







          I'm using Windows 10. jdk 11.0.1

          – Adrian
          Nov 16 '18 at 20:59















          okay, which version java? and do you any .java files in that directory, you should execute this from that directory

          – Deadpool
          Nov 16 '18 at 20:59





          okay, which version java? and do you any .java files in that directory, you should execute this from that directory

          – Deadpool
          Nov 16 '18 at 20:59













          Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

          – Adrian
          Nov 16 '18 at 21:02





          Java version 8, update 191. My folder looks like this: imgur.com/a/FWiKihM . And yes, I'm nonstop within that directory.

          – Adrian
          Nov 16 '18 at 21:02













          0














          Since your paths contain space they has to be quoted. You can do it by iterating over sources.txt in a loop and quoting the entire line:



          FOR /F %%i IN (sources.txt) DO "javac %%i"


          or you can try dir /x to generate sources.txt with a short path as per dir docs




          /x



          Displays the short names generated for non-8dot3 file names. The display is the same as the display for /n, but the short name is inserted before the long name.




          One way or another, scripting in Windows Batch sux.






          share|improve this answer


























          • If this would help then %%i was unexpected at this time.

            – Adrian
            Nov 16 '18 at 21:10











          • @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

            – Karol Dowbecki
            Nov 16 '18 at 21:13













          • My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

            – Adrian
            Nov 16 '18 at 21:16











          • @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

            – Karol Dowbecki
            Nov 16 '18 at 21:19











          • I have updated this question with my main.java code.

            – Adrian
            Nov 16 '18 at 21:23
















          0














          Since your paths contain space they has to be quoted. You can do it by iterating over sources.txt in a loop and quoting the entire line:



          FOR /F %%i IN (sources.txt) DO "javac %%i"


          or you can try dir /x to generate sources.txt with a short path as per dir docs




          /x



          Displays the short names generated for non-8dot3 file names. The display is the same as the display for /n, but the short name is inserted before the long name.




          One way or another, scripting in Windows Batch sux.






          share|improve this answer


























          • If this would help then %%i was unexpected at this time.

            – Adrian
            Nov 16 '18 at 21:10











          • @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

            – Karol Dowbecki
            Nov 16 '18 at 21:13













          • My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

            – Adrian
            Nov 16 '18 at 21:16











          • @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

            – Karol Dowbecki
            Nov 16 '18 at 21:19











          • I have updated this question with my main.java code.

            – Adrian
            Nov 16 '18 at 21:23














          0












          0








          0







          Since your paths contain space they has to be quoted. You can do it by iterating over sources.txt in a loop and quoting the entire line:



          FOR /F %%i IN (sources.txt) DO "javac %%i"


          or you can try dir /x to generate sources.txt with a short path as per dir docs




          /x



          Displays the short names generated for non-8dot3 file names. The display is the same as the display for /n, but the short name is inserted before the long name.




          One way or another, scripting in Windows Batch sux.






          share|improve this answer















          Since your paths contain space they has to be quoted. You can do it by iterating over sources.txt in a loop and quoting the entire line:



          FOR /F %%i IN (sources.txt) DO "javac %%i"


          or you can try dir /x to generate sources.txt with a short path as per dir docs




          /x



          Displays the short names generated for non-8dot3 file names. The display is the same as the display for /n, but the short name is inserted before the long name.




          One way or another, scripting in Windows Batch sux.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 21:11

























          answered Nov 16 '18 at 21:07









          Karol DowbeckiKarol Dowbecki

          26.8k93860




          26.8k93860













          • If this would help then %%i was unexpected at this time.

            – Adrian
            Nov 16 '18 at 21:10











          • @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

            – Karol Dowbecki
            Nov 16 '18 at 21:13













          • My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

            – Adrian
            Nov 16 '18 at 21:16











          • @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

            – Karol Dowbecki
            Nov 16 '18 at 21:19











          • I have updated this question with my main.java code.

            – Adrian
            Nov 16 '18 at 21:23



















          • If this would help then %%i was unexpected at this time.

            – Adrian
            Nov 16 '18 at 21:10











          • @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

            – Karol Dowbecki
            Nov 16 '18 at 21:13













          • My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

            – Adrian
            Nov 16 '18 at 21:16











          • @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

            – Karol Dowbecki
            Nov 16 '18 at 21:19











          • I have updated this question with my main.java code.

            – Adrian
            Nov 16 '18 at 21:23

















          If this would help then %%i was unexpected at this time.

          – Adrian
          Nov 16 '18 at 21:10





          If this would help then %%i was unexpected at this time.

          – Adrian
          Nov 16 '18 at 21:10













          @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

          – Karol Dowbecki
          Nov 16 '18 at 21:13







          @Adrian the root cause is your paths containing a space. Since I'm not a windows batch expert nor I have access to windows command prompt I can't really help, sorry. Your goal is to run javac "C:UsersAdrian $ProjectFile.java" command or similar using escaped path to File.java.

          – Karol Dowbecki
          Nov 16 '18 at 21:13















          My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

          – Adrian
          Nov 16 '18 at 21:16





          My files finally do compile but they're "refusing" to run... Here's the image of my folder structure imgur.com/a/FWiKihM . I'm using java Main command to compile it although it gives me the error Error: Could not find or load main class Main and I am within the same directory as my Main class

          – Adrian
          Nov 16 '18 at 21:16













          @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

          – Karol Dowbecki
          Nov 16 '18 at 21:19





          @Adrian open a new question and post the entire Main class, there is not enough detail to answer this.

          – Karol Dowbecki
          Nov 16 '18 at 21:19













          I have updated this question with my main.java code.

          – Adrian
          Nov 16 '18 at 21:23





          I have updated this question with my main.java code.

          – Adrian
          Nov 16 '18 at 21:23


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345175%2fcompile-multiple-classes-and-pass-command-line-arguments%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine