Bom Dia, Tenho um aplicação que rodará em 5 máquinas, a minha será o servidor, ao realizar os teste na minha máquina a conexão funciona normalmente pois estou utilizando o localhost:3306 .
Mas quando altero para o ip da minha maquina e crio o .JAR e executo em outro PC e não dá erro de conexão ao banco.
public static Connection conector() {
java.sql.Connection conexao = null;
String driver = "com.mysql.jdbc.Driver";
// alterei o localhost:3306 para o IP da minha maquina
String url = "jdbc:mysql://xx.xx.xx.xx/db_controleci";
String user = "root";
String password = "";
try {
Class.forName(driver);
conexao = DriverManager.getConnection(url, user, password);
return conexao;
} catch (Exception e) {
System.out.println(e);
return null;
}
Instalei o workbenck na outra maquina e dei o privilegio grant no mysql e consegui configurar o banco remotamente, mas o . JAR não consegui.
Abner bom dia, agora eu coloquei dessa forma :
String url = “jdbc:mysql://10.38.128.21/localhost:3306/db_controleci”;
informa que minha maquina não tem permissão ao BD.
java.sql.SQLException: null, message from server: “Host ‘micro005’ is not allowed to connect to this MariaDB server”
Funcionou na rede, mas ao construir o projeto ele cria uma pasta lib com os drivers. Para funcionar precisei levar o .JAR juntamente com a pasta lib. Teria alguma maneira que eu possa fazer para não ter que levar a pasta lib?
Sim, vai em “Files”, seleciona o seu projeto, e procura o arquivo chamado build.xml. E aí cola isso depois dos comentários:
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
Opa! Boa tarde, tem certeza que fez o procedimento correto? Abriu o arquivo da pasta store? Porquê eu utilizo esse meio sempre e os arquivos sempre acoplam tudo no .jar.
Tenta abrir o .jar pelo CMD e vê qual erro apresenta pra você, aí você retorna
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
<target name="-post-jar">
<property name="store.jar.name" value="${application.title}"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${store.jar.name} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/.SF, META-INF/.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
-->
Quando executo pelo CMD ele não consegue localizar a classe principal, mesmo com a pasta lib junto com o .JAR
<?xml version="1.0" encoding="UTF-8"?>
Builds, tests, and runs the project ProjetoCI.
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="ProjetoCI-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
<target name="-post-jar">
<property name="store.jar.name" value="${application.title}"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${store.jar.name} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/.SF, META-INF/.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>