Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Module name should be same as Directory name?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
└── src
   └── calculator
       ├── com
       │   └── ngsharma
       │       └── oca
       │           └── Calculator.java
       └── module-info.java


Calculator.java


module-info.java




Compile this above program




.
├── out
│   └── calc-module <--- Directory name changed
│       ├── com
│       │   └── ngsharma
│       │       └── oca
│       │           └── Calculator.class
│       └── module-info.class



Run this above program




Q1. module-info.java file name should be same as Calculator directory name or not

Compiled this module throw error:


Run this module throw error:



 
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the directory name does not have to match the module name. That said, it's good practice.

However, the --add-modules and the -p options don't take directory names as their arguments, but module names. Your module is named 'calc', regardless of the directory it appears in.

By the way, you really shouldn't have to use --add-modules at all unless you depend on automatic modules that in turn depend on other modules.

Here's how you compile and run your application:
 
Ng Sharma
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's how you compile and run your application:


javac -d out --module-source-path src -m calc
Run Compile command throws

error: module calc not found in module source path
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies. I just tested it out, and yes it appears that the module's directory must have the same name as the module.

The commands I posted will work if you rename the directory calc-module to calc.

[edit]

It's also --module-source-path, and not -module-source-path. I really ought to test my code snippets before I post them here.
 
Greenhorn
Posts: 22
VI Editor Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to have module name different as name of parent directory, however, it is NOT recommended, and you are not able to use '--module-source-path' option,  but you are still able to use '--module-path' option, as there you can provide directory path.
 
Nothing up my sleeve ... and ... presto! A tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!