The linerange
option of \lstlistinginput
allows you to specify arbitrary start and stop text (appropriately escaped). So here is one working version:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstinputlisting[linerange=//\ Begin\ Identifier1-//\ End\ Identifier1]{a.jar}
\end{document}
with a.jar
containing
// Begin Identifier0
// #Identifier0#
// This is our class [...]
// #Identifier0#
public class Anyclass{
// #Identifier0#
// the constructor is here...
}
// End Identifier0
// Begin Identifier1
// #Identifier1#
// This is our class [...]
// #Identifier1#
public class Anyclass{
// #Identifier1#
// the constructor is here...
// #Identifier2#
public Anyclass(){
}
}
// End Identifier1
// Begin Identifier3
// #Identifier3#
// This is our class [...]
// #Identifier3#
public class Anyclass{
// #Identifier3#
// the constructor is here...
// #Identifier2#
public Anyclass(){
}
}
// End Identifier3
produces
Note that I have added comment lines that are clearly unique for this purpose. Also note the escaping of the space characters.
If you do not want the start and stop text included in the output you can add the option includerangemarker=false
to the \lstinputlisting
call or set this option globally via
\lstset{includerangemarker=false}