Отказ от ответственности : я не знаю, разрешено ли это по hibernate
лицензии
Вы можете извлечь org.hibernate.annotations
пакетк вашей последней банке.У вас будет зависимость времени компиляции от hibernate-core
, но в ваш окончательный jar будет включен только пакет org.hibernate.annotations
.
Использование maven-dependency-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>extract-hibernate-annotations</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<includes>org/hibernate/annotations/**</includes>
</configuration>
</execution>
</executions>
</plugin>
И вам придетсядобавьте hibernate-core
в качестве предоставленной зависимости:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
<scope>provided</scope>
</dependency>
Тестирование:
Main.java
:
import org.hibernate.annotations.SQLDelete;
@SQLDelete(sql = "delete from whatever where id = ?")
public class Main {
public static void main(String[] args) {
SQLDelete annotation = Main.class.getAnnotation(SQLDelete.class);
System.out.println("Sql delete = " + annotation);
System.out.println("Sql = " + annotation.sql());
try {
Class.forName("org.hibernate.Session");
} catch (ClassNotFoundException e) {
System.out.println("org.hibernate.Session is not present");
}
}
}
pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.caco3</groupId>
<artifactId>so</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>extract-hibernate-annotations</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<includes>org/hibernate/annotations/**</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
Main
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Сборка:
$ mvn package
$ java -jar target/so-1.0-SNAPSHOT.jar
Выход:
Sql delete = @org.hibernate.annotations.SQLDelete(callable=false, check=NONE, sql=delete from whatever where id = ?)
Sql = delete from whatever where id = ?
org.hibernate.Session is not present
Содержимое банки:
├── Main.class
├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ └── com.caco3
│ └── so
│ ├── pom.properties
│ └── pom.xml
└── org
└── hibernate
└── annotations
├── AccessType.class
├── Any.class
├── AnyMetaDef.class
├── AnyMetaDefs.class
├── AttributeAccessor.class
├── BatchSize.class
├── Cache.class
├── CacheConcurrencyStrategy$1.class
├── CacheConcurrencyStrategy.class
├── CacheModeType$1.class
├── CacheModeType.class
├── Cascade.class
├── CascadeType.class
├── Check.class
├── CollectionId.class
├── CollectionType.class
├── ColumnDefault.class
├── Columns.class
├── ColumnTransformer.class
├── ColumnTransformers.class
├── CreationTimestamp.class
├── DiscriminatorFormula.class
├── DiscriminatorOptions.class
├── DynamicInsert.class
├── DynamicUpdate.class
├── Entity.class
├── Fetch.class
├── FetchMode.class
├── FetchProfile$FetchOverride.class
├── FetchProfile.class
├── FetchProfiles.class
├── Filter.class
├── FilterDef.class
├── FilterDefs.class
├── FilterJoinTable.class
├── FilterJoinTables.class
├── Filters.class
├── FlushModeType.class
├── ForeignKey.class
├── Formula.class
├── Generated.class
├── GenerationTime.class
├── GeneratorType.class
├── GenericGenerator.class
├── GenericGenerators.class
├── Immutable.class
├── Index.class
├── IndexColumn.class
├── JoinColumnOrFormula.class
├── JoinColumnsOrFormulas.class
├── JoinFormula.class
├── LazyCollection.class
├── LazyCollectionOption.class
├── LazyGroup.class
├── LazyToOne.class
├── LazyToOneOption.class
├── ListIndexBase.class
├── Loader.class
├── ManyToAny.class
├── MapKeyType.class
├── MetaValue.class
├── NamedNativeQueries.class
├── NamedNativeQuery.class
├── NamedQueries.class
├── NamedQuery.class
├── Nationalized.class
├── NaturalIdCache.class
├── NaturalId.class
├── NotFoundAction.class
├── NotFound.class
├── OnDeleteAction.class
├── OnDelete.class
├── OptimisticLock.class
├── OptimisticLocking.class
├── OptimisticLockType.class
├── OrderBy.class
├── ParamDef.class
├── Parameter.class
├── Parent.class
├── Persister.class
├── Polymorphism.class
├── PolymorphismType.class
├── Proxy.class
├── QueryHints.class
├── ResultCheckStyle.class
├── RowId.class
├── SelectBeforeUpdate.class
├── Sort.class
├── SortComparator.class
├── SortNatural.class
├── SortType.class
├── Source.class
├── SourceType.class
├── SQLDeleteAll.class
├── SQLDelete.class
├── SqlFragmentAlias.class
├── SQLInsert.class
├── SQLUpdate.class
├── Subselect.class
├── Synchronize.class
├── Table.class
├── Tables.class
├── Target.class
├── Tuplizer.class
├── Tuplizers.class
├── Type.class
├── TypeDef.class
├── TypeDefs.class
├── UpdateTimestamp.class
├── ValueGenerationType.class
├── Where.class
└── WhereJoinTable.class