"mvn dependency:build-classpath" - Generate Class Pass

Q

How to generate class path for dependences with Maven?

✍: FYIcenter.com

A

If you run your application JAR file generated from Maven, you need to include JAR files of all dependences in the class path. One way to build this class path is to use the "mvn dependency:build-classpath" command.

1. Generate class path of all dependences, using the previous application as an example.

fyicenter$ cd bio
fyicenter$ ../apache-maven-3.8.7/bin/mvn dependency:build-classpath -Dmdep.outputFile=cp.txt

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.fyicenter:bio >--------------------------
[INFO] Building BioJava Test 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:build-classpath (default-cli) @ bio ---
[INFO] Wrote classpath file '/home/fyicenter/packages/java/bio/cp.txt'.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
...

2. Export the class path as an environment variable.

fyicenter$ export BioJava_Path=`cat cp.txt` 

3. Run the test program with the class path.

fyicenter$ java -cp target/bio-1.0.jar:$BioJava_Path com.fyicenter.FastaReaderTeat example.fasta 

01:05:49 [main] WARN  org.biojava.nbio.core.sequence.io.FastaReader - 
  Sequence with header 'seq1' has unrecognised compounds (Cannot find compound for:  ), 
  it will be ignored

1 : seq0 FQTWEEFSRAAEKLYLADPMKVRVVLKYRHVDGNLCIKVTDDLVCLVYRTDQAQDVKKIEKF
2 : seq2 EEYQTWEEFARAAEKLYLTDPMKVRVVLKYRHCDGNLCMKVTDDAVCLQYKTDQAQDVKKVEKLHGK
3 : seq3 MYQVWEEFSRAVEKLYLTDPMKVRVVLKYRHCDGNLCIKVTDNSVCLQYKTDQAQDVK
4 : seq4 EEFSRAVEKLYLTDPMKVRVVLKYRHCDGNLCIKVTDNSVVSYEMRLFGVQKDNFALEHSLL
5 : seq5 SWEEFAKAAEVLYLEDPMKCRMCTKYRHVDHKLVVKLTDNHTVLKYVTDMAQDVKKIEKLTTLLMR
6 : seq6 FTNWEEFAKAAERLHSANPEKCRFVTKYNHTKGELVLKLTDDVVCLQYSTNQLQDVKKLEKLSSTLLRSI
7 : seq7 SWEEFVERSVQLFRGDPNATRYVMKYRHCEGKLVLKVTDDRECLKFKTDQAQDAKKMEKLNNIFF
8 : seq8 SWDEFVDRSVQLFRADPESTRYVMKYRHCDGKLVLKVTDNKECLKFKTDQAQEAKKMEKLNNIFFTLM
9 : seq9 KNWEDFEIAAENMYMANPQNCRYTMKYVHSKGHILLKMSDNVKCVQYRAENMPDLKK
10 : seq10 FDSWDEFVSKSVELFRNHPDTTRYVVKYRHCEGKLVLKVTDNHECLKFKTDQAQDAKKMEK

As you can see, the test program FastaReaderTeat.java is running correctly now. It reported an warning on the "seq1" sequence and skipped it in the output.

 

BioPerl - Perl Bioinformatics Toolkit

Read FASTA File with FastaReaderTeat.java

BioJava - Java Bioinformatics Toolkit

⇑⇑ OBF (Open Bioinformatics Foundation) Tools

2023-04-17, 225👍, 0💬