0

I have a directory structure like this:

TestJlink

-src

--module-info.java

--com

---company

----TestJLink

-----TestJLink.java

I run this jlink --module-path src --add-modules com.company.TestJLink --output outputJRE

I get Error: Module com.company.TestJlink not found

The contents of my module-info.java is this:

module com.company.TestJlink {
        
  requires java.desktop;
    
  requires com.microsoft.sqlserver.jdbc;
        
  requires java.sql;
        
  requires sshj;
    
}

My TestJLink.java contains this

package com.company.TestJLink;
imports ...
public class TestJLink {
    TestJlink(){}
...
}

I am using java 11

I am able to build it using this: java -p C:\Users\Administrator...\target\classes;C:\Users\Administrator.m2\repository\com\microsoft\sqlserver\mssql-jdbc\8.4.1.jre11\mssql-jdbc-8.4.1.jre11.jar;C:\Users\Administrator.m2\repository\com\hierynomus\sshj\0.27.0\sshj-0.27.0.jar;C:\Users\Administrator.m2\repository\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar;C:\Users\Administrator.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar;C:\Users\Administrator.m2\repository\com\jcraft\jzlib\1.1.3\jzlib-1.1.3.jar;C:\Users\Administrator.m2\repository\net\i2p\crypto\eddsa\0.2.0\eddsa-0.2.0.jar;C:\Users\Administrator.m2\repository\org\slf4j\slf4j-api\1.7.5\slf4j-api-1.7.5.jar;C:\Users\Administrator.m2\repository\org\slf4j\slf4j-log4j12\1.7.5\slf4j-log4j12-1.7.5.jar;C:\Users\Administrator.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar -m com.company.TestJLink/com.company.TestJLink.TestJLink

coloradoman
  • 341
  • 1
  • 5
  • 11
  • ..by making sure your module has been produced as an output on the path you've specified. that would obviously be a pre-requisite of executing the `jlink` command. so, time to visit back the tutorial or documentation guiding you to create standalone JRE. – Naman Dec 30 '20 at 14:37
  • @Naman So you are saying I need an output directory? Yes I am able to build and run the TestJLlink class. It creates an output directory. Is there something else I a missing. Its just when I try to create a jre it fails. I am trying those tutorials and no luck. – coloradoman Dec 30 '20 at 14:40
  • link them, let's see what are you missing, or does the tutorial need a fix itself. – Naman Dec 30 '20 at 14:49
  • @Naman this is what I am using https://www.geeksforgeeks.org/jlink-java-linker/ – coloradoman Dec 30 '20 at 14:59
  • and what is the value of your `--module-path` in the command you are using to link versus the one you are using to execute? – Naman Dec 30 '20 at 15:03
  • Are you really using `jlink --module-path src`? Surely the JDBC and sshj modules aren’t in `src`, are they? And do you know for certain that those .jar files are modular .jar files? – VGR Dec 31 '20 at 15:42
  • @VGR I also was using a -p to all the maven dependencies. – coloradoman Jan 04 '21 at 21:53
  • `-p` is the same as `--module-path`. If you use both, I suspect one replaces the other. That would explain why the jlink command ignores your `--module-path` argument, and therefore does not see the module located in `src`. Solution: add `src` to the argument given to `-p`. – VGR Jan 04 '21 at 21:57
  • @VGR did you see my answer I just posted? I got it to work kinda, if you know a solution to that auto modules let me know. It think its going to be a pain in the ass to get them to include the module-info.java – coloradoman Jan 04 '21 at 21:59

1 Answers1

0

solved it by first doing javac which I was also having problems with. The solution I found was just to add this to the end of the javac src\module-info.java src\com\company\TestJLink\TestJLink.java

After it was compiled, I was able to jlink it. The problem I had earlier with jlinking it was I was referencing the src, not the compiled .class files.

jlink --module-path --output testjre --add-modules com.company.TestJLink -p ... any other dependencies from maven jars etc.

Now I am getting this error, Error: automatic module cannot be used with jlink. This should be fun, but it has to do with my maven dependencies and not the actual example.

coloradoman
  • 341
  • 1
  • 5
  • 11