0

I am trying to write a standalone Java application in IntelliJ using edu.stanford.nlp.trees.GrammaticalStructure. Therefore, I have imported the module:

import edu.stanford.nlp.trees.GrammaticalStructure;

Currently, Intellij doesn't recognize this and many others of the imported external libraries (cannot resolve the symbols) and is also not able to automatically download/import them.

Is there a way to use the GrammaticalStructure class without having to download the entire Stanford CoreNLP .jar and adding it to the project as a library? This question applies to other dependencies as well, since I want to use other external libraries but avoid including their .jar files as much as possible (to minimize the size of the final application, given that it will be standalone). Unfortunately, all the solutions I have found proposed exactly that.

Apologies if I have overlooked some basic setting or setup steps, it has been a while since I have worked with Java.

Any help is greatly appreciated.

mike_thecode
  • 171
  • 2
  • 6
cactus
  • 345
  • 4
  • 13

1 Answers1

1

If you want to use it means you want to execute the code in them. How is the runtime supposed to execute code that is does not have? How is the compiler supposed to know how the code is defined (e.g. what the classes look like)? This is simply impossible. If you want to use the code you have to provide it to the compiler as well as the runtime.

If you just dont want to include all of that code into your application, you need either access to the sources and just pick the class you need or you need some kind of JAR minimizer as @CrazyCoder suggested.

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
  • He doesn't want to use the jars. The other option would be to obtain the sources of these libraries and include them into the project manually removing the source files he doesn't need. Or strip the unused classes from the final jars via obfuscators/plug-ins. – CrazyCoder Mar 11 '21 at 19:51
  • Whats the sense of the import then, if he does not want to use it? – EricSchaefer Mar 11 '21 at 19:52
  • It looks like he needs just SOME classes (say minimal required dependencies to build and run the code), not the whole jar which may contain classes that would not be used by his code. – CrazyCoder Mar 11 '21 at 19:53
  • But that still means he needs that code somehow. – EricSchaefer Mar 11 '21 at 19:55
  • 1
    He states: "I want to use other external libraries but avoid including their .jar files as much as possible (to minimise the size of the final application, given that it will be a standalone).". Which means he is OK with using the code provided by the dependencies, but not the extra code which may be contained in the jars and would not be needed for his apps. The key word seems to be "as much as possible". – CrazyCoder Mar 11 '21 at 19:58
  • This means the wording is a bit off. It sound an awful lot like he does not want to download, while actually does not want to include all the code. You are probably right about that. – EricSchaefer Mar 11 '21 at 20:01
  • I suppose I may have expressed myself inprecisely, sorry for that, English is not my first language. I will take a look at the .jar minimisers proposed by CrazyCoder since they seem to be close in functionality to what I am looking for. Thanks for the help. – cactus Mar 11 '21 at 20:20